home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / gnus / gnus-sum.el.z / gnus-sum.el
Encoding:
Text File  |  1998-05-21  |  307.3 KB  |  8,737 lines

  1. ;;; gnus-sum.el --- summary mode commands for Gnus
  2. ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
  3.  
  4. ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
  5. ;; Keywords: news
  6.  
  7. ;; This file is part of GNU Emacs.
  8.  
  9. ;; GNU Emacs is free software; you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13.  
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
  17. ;; GNU General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  21. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22. ;; Boston, MA 02111-1307, USA.
  23.  
  24. ;;; Commentary:
  25.  
  26. ;;; Code:
  27.  
  28. (eval-when-compile (require 'cl))
  29.  
  30. (require 'gnus)
  31. (require 'gnus-group)
  32. (require 'gnus-spec)
  33. (require 'gnus-range)
  34. (require 'gnus-int)
  35. (require 'gnus-undo)
  36.  
  37. (defcustom gnus-kill-summary-on-exit t
  38.   "*If non-nil, kill the summary buffer when you exit from it.
  39. If nil, the summary will become a \"*Dead Summary*\" buffer, and
  40. it will be killed sometime later."
  41.   :group 'gnus-summary-exit
  42.   :type 'boolean)
  43.  
  44. (defcustom gnus-fetch-old-headers nil
  45.   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
  46. If an unread article in the group refers to an older, already read (or
  47. just marked as read) article, the old article will not normally be
  48. displayed in the Summary buffer.  If this variable is non-nil, Gnus
  49. will attempt to grab the headers to the old articles, and thereby
  50. build complete threads.     If it has the value `some', only enough
  51. headers to connect otherwise loose threads will be displayed.
  52. This variable can also be a number.  In that case, no more than that
  53. number of old headers will be fetched.
  54.  
  55. The server has to support NOV for any of this to work."
  56.   :group 'gnus-thread
  57.   :type '(choice (const :tag "off" nil)
  58.          (const some)
  59.          number
  60.          (sexp :menu-tag "other" t)))
  61.  
  62. (defcustom gnus-summary-make-false-root 'adopt
  63.   "*nil means that Gnus won't gather loose threads.
  64. If the root of a thread has expired or been read in a previous
  65. session, the information necessary to build a complete thread has been
  66. lost.  Instead of having many small sub-threads from this original thread
  67. scattered all over the summary buffer, Gnus can gather them.
  68.  
  69. If non-nil, Gnus will try to gather all loose sub-threads from an
  70. original thread into one large thread.
  71.  
  72. If this variable is non-nil, it should be one of `none', `adopt',
  73. `dummy' or `empty'.
  74.  
  75. If this variable is `none', Gnus will not make a false root, but just
  76. present the sub-threads after another.
  77. If this variable is `dummy', Gnus will create a dummy root that will
  78. have all the sub-threads as children.
  79. If this variable is `adopt', Gnus will make one of the \"children\"
  80. the parent and mark all the step-children as such.
  81. If this variable is `empty', the \"children\" are printed with empty
  82. subject fields.     (Or rather, they will be printed with a string
  83. given by the `gnus-summary-same-subject' variable.)"
  84.   :group 'gnus-thread
  85.   :type '(choice (const :tag "off" nil)
  86.          (const none)
  87.          (const dummy)
  88.          (const adopt)
  89.          (const empty)))
  90.  
  91. (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
  92.   "*A regexp to match subjects to be excluded from loose thread gathering.
  93. As loose thread gathering is done on subjects only, that means that
  94. there can be many false gatherings performed.  By rooting out certain
  95. common subjects, gathering might become saner."
  96.   :group 'gnus-thread
  97.   :type 'regexp)
  98.  
  99. (defcustom gnus-summary-gather-subject-limit nil
  100.   "*Maximum length of subject comparisons when gathering loose threads.
  101. Use nil to compare full subjects.  Setting this variable to a low
  102. number will help gather threads that have been corrupted by
  103. newsreaders chopping off subject lines, but it might also mean that
  104. unrelated articles that have subject that happen to begin with the
  105. same few characters will be incorrectly gathered.
  106.  
  107. If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
  108. comparing subjects."
  109.   :group 'gnus-thread
  110.   :type '(choice (const :tag "off" nil)
  111.          (const fuzzy)
  112.          (sexp :menu-tag "on" t)))
  113.  
  114. (defcustom gnus-simplify-ignored-prefixes nil
  115.   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
  116.   :group 'gnus-thread
  117.   :type '(choice (const :tag "off" nil)
  118.          regexp))
  119.  
  120. (defcustom gnus-build-sparse-threads nil
  121.   "*If non-nil, fill in the gaps in threads.
  122. If `some', only fill in the gaps that are needed to tie loose threads
  123. together.  If `more', fill in all leaf nodes that Gnus can find.  If
  124. non-nil and non-`some', fill in all gaps that Gnus manages to guess."
  125.   :group 'gnus-thread
  126.   :type '(choice (const :tag "off" nil)
  127.          (const some)
  128.          (const more)
  129.          (sexp :menu-tag "all" t)))
  130.  
  131. (defcustom gnus-summary-thread-gathering-function
  132.   'gnus-gather-threads-by-subject
  133.   "Function used for gathering loose threads.
  134. There are two pre-defined functions: `gnus-gather-threads-by-subject',
  135. which only takes Subjects into consideration; and
  136. `gnus-gather-threads-by-references', which compared the References
  137. headers of the articles to find matches."
  138.   :group 'gnus-thread
  139.   :type '(radio (function-item gnus-gather-threads-by-subject)
  140.         (function-item gnus-gather-threads-by-references)
  141.         (function :tag "other")))
  142.  
  143. ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
  144. (defcustom gnus-summary-same-subject ""
  145.   "*String indicating that the current article has the same subject as the previous.
  146. This variable will only be used if the value of
  147. `gnus-summary-make-false-root' is `empty'."
  148.   :group 'gnus-summary-format
  149.   :type 'string)
  150.  
  151. (defcustom gnus-summary-goto-unread t
  152.   "*If t, marking commands will go to the next unread article.
  153. If `never', commands that usually go to the next unread article, will
  154. go to the next article, whether it is read or not.
  155. If nil, only the marking commands will go to the next (un)read article."
  156.   :group 'gnus-summary-marks
  157.   :link '(custom-manual "(gnus)Setting Marks")
  158.   :type '(choice (const :tag "off" nil)
  159.          (const never)
  160.          (sexp :menu-tag "on" t)))
  161.  
  162. (defcustom gnus-summary-default-score 0
  163.   "*Default article score level.
  164. All scores generated by the score files will be added to this score.
  165. If this variable is nil, scoring will be disabled."
  166.   :group 'gnus-score-default
  167.   :type '(choice (const :tag "disable")
  168.          integer))
  169.  
  170. (defcustom gnus-summary-zcore-fuzz 0
  171.   "*Fuzziness factor for the zcore in the summary buffer.
  172. Articles with scores closer than this to `gnus-summary-default-score'
  173. will not be marked."
  174.   :group 'gnus-summary-format
  175.   :type 'integer)
  176.  
  177. (defcustom gnus-simplify-subject-fuzzy-regexp nil
  178.   "*Strings to be removed when doing fuzzy matches.
  179. This can either be a regular expression or list of regular expressions
  180. that will be removed from subject strings if fuzzy subject
  181. simplification is selected."
  182.   :group 'gnus-thread
  183.   :type '(repeat regexp))
  184.  
  185. (defcustom gnus-show-threads t
  186.   "*If non-nil, display threads in summary mode."
  187.   :group 'gnus-thread
  188.   :type 'boolean)
  189.  
  190. (defcustom gnus-thread-hide-subtree nil
  191.   "*If non-nil, hide all threads initially.
  192. If threads are hidden, you have to run the command
  193. `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
  194. to expose hidden threads."
  195.   :group 'gnus-thread
  196.   :type 'boolean)
  197.  
  198. (defcustom gnus-thread-hide-killed t
  199.   "*If non-nil, hide killed threads automatically."
  200.   :group 'gnus-thread
  201.   :type 'boolean)
  202.  
  203. (defcustom gnus-thread-ignore-subject nil
  204.   "*If non-nil, ignore subjects and do all threading based on the Reference header.
  205. If nil, which is the default, articles that have different subjects
  206. from their parents will start separate threads."
  207.   :group 'gnus-thread
  208.   :type 'boolean)
  209.  
  210. (defcustom gnus-thread-operation-ignore-subject t
  211.   "*If non-nil, subjects will be ignored when doing thread commands.
  212. This affects commands like `gnus-summary-kill-thread' and
  213. `gnus-summary-lower-thread'.
  214.  
  215. If this variable is nil, articles in the same thread with different
  216. subjects will not be included in the operation in question.  If this
  217. variable is `fuzzy', only articles that have subjects that are fuzzily
  218. equal will be included."
  219.   :group 'gnus-thread
  220.   :type '(choice (const :tag "off" nil)
  221.          (const fuzzy)
  222.          (sexp :tag "on" t)))
  223.  
  224. (defcustom gnus-thread-indent-level 4
  225.   "*Number that says how much each sub-thread should be indented."
  226.   :group 'gnus-thread
  227.   :type 'integer)
  228.  
  229. (defcustom gnus-auto-extend-newsgroup t
  230.   "*If non-nil, extend newsgroup forward and backward when requested."
  231.   :group 'gnus-summary-choose
  232.   :type 'boolean)
  233.  
  234. (defcustom gnus-auto-select-first t
  235.   "*If nil, don't select the first unread article when entering a group.
  236. If this variable is `best', select the highest-scored unread article
  237. in the group.  If neither nil nor `best', select the first unread
  238. article.
  239.  
  240. If you want to prevent automatic selection of the first unread article
  241. in some newsgroups, set the variable to nil in
  242. `gnus-select-group-hook'."
  243.   :group 'gnus-group-select
  244.   :type '(choice (const :tag "none" nil)
  245.          (const best)
  246.          (sexp :menu-tag "first" t)))
  247.  
  248. (defcustom gnus-auto-select-next t
  249.   "*If non-nil, offer to go to the next group from the end of the previous.
  250. If the value is t and the next newsgroup is empty, Gnus will exit
  251. summary mode and go back to group mode.     If the value is neither nil
  252. nor t, Gnus will select the following unread newsgroup.     In
  253. particular, if the value is the symbol `quietly', the next unread
  254. newsgroup will be selected without any confirmation, and if it is
  255. `almost-quietly', the next group will be selected without any
  256. confirmation if you are located on the last article in the group.
  257. Finally, if this variable is `slightly-quietly', the `Z n' command
  258. will go to the next group without confirmation."
  259.   :group 'gnus-summary-maneuvering
  260.   :type '(choice (const :tag "off" nil)
  261.          (const quietly)
  262.          (const almost-quietly)
  263.          (const slightly-quietly)
  264.          (sexp :menu-tag "on" t)))
  265.  
  266. (defcustom gnus-auto-select-same nil
  267.   "*If non-nil, select the next article with the same subject."
  268.   :group 'gnus-summary-maneuvering
  269.   :type 'boolean)
  270.  
  271. (defcustom gnus-summary-check-current nil
  272.   "*If non-nil, consider the current article when moving.
  273. The \"unread\" movement commands will stay on the same line if the
  274. current article is unread."
  275.   :group 'gnus-summary-maneuvering
  276.   :type 'boolean)
  277.  
  278. (defcustom gnus-auto-center-summary t
  279.   "*If non-nil, always center the current summary buffer.
  280. In particular, if `vertical' do only vertical recentering.  If non-nil
  281. and non-`vertical', do both horizontal and vertical recentering."
  282.   :group 'gnus-summary-maneuvering
  283.   :type '(choice (const :tag "none" nil)
  284.          (const vertical)
  285.          (sexp :menu-tag "both" t)))
  286.  
  287. (defcustom gnus-show-all-headers nil
  288.   "*If non-nil, don't hide any headers."
  289.   :group 'gnus-article-hiding
  290.   :group 'gnus-article-headers
  291.   :type 'boolean)
  292.  
  293. (defcustom gnus-summary-ignore-duplicates nil
  294.   "*If non-nil, ignore articles with identical Message-ID headers."
  295.   :group 'gnus-summary
  296.   :type 'boolean)
  297.   
  298. (defcustom gnus-single-article-buffer t
  299.   "*If non-nil, display all articles in the same buffer.
  300. If nil, each group will get its own article buffer."
  301.   :group 'gnus-article-various
  302.   :type 'boolean)
  303.  
  304. (defcustom gnus-break-pages t
  305.   "*If non-nil, do page breaking on articles.
  306. The page delimiter is specified by the `gnus-page-delimiter'
  307. variable."
  308.   :group 'gnus-article-various
  309.   :type 'boolean)
  310.  
  311. (defcustom gnus-show-mime nil
  312.   "*If non-nil, do mime processing of articles.
  313. The articles will simply be fed to the function given by
  314. `gnus-show-mime-method'."
  315.   :group 'gnus-article-mime
  316.   :type 'boolean)
  317.  
  318. (defcustom gnus-move-split-methods nil
  319.   "*Variable used to suggest where articles are to be moved to.
  320. It uses the same syntax as the `gnus-split-methods' variable."
  321.   :group 'gnus-summary-mail
  322.   :type '(repeat (choice (list function)
  323.              (cons regexp (repeat string))
  324.              sexp)))
  325.  
  326. (defcustom gnus-unread-mark ? 
  327.   "*Mark used for unread articles."
  328.   :group 'gnus-summary-marks
  329.   :type 'character)
  330.  
  331. (defcustom gnus-ticked-mark ?!
  332.   "*Mark used for ticked articles."
  333.   :group 'gnus-summary-marks
  334.   :type 'character)
  335.  
  336. (defcustom gnus-dormant-mark ??
  337.   "*Mark used for dormant articles."
  338.   :group 'gnus-summary-marks
  339.   :type 'character)
  340.  
  341. (defcustom gnus-del-mark ?r
  342.   "*Mark used for del'd articles."
  343.   :group 'gnus-summary-marks
  344.   :type 'character)
  345.  
  346. (defcustom gnus-read-mark ?R
  347.   "*Mark used for read articles."
  348.   :group 'gnus-summary-marks
  349.   :type 'character)
  350.  
  351. (defcustom gnus-expirable-mark ?E
  352.   "*Mark used for expirable articles."
  353.   :group 'gnus-summary-marks
  354.   :type 'character)
  355.  
  356. (defcustom gnus-killed-mark ?K
  357.   "*Mark used for killed articles."
  358.   :group 'gnus-summary-marks
  359.   :type 'character)
  360.  
  361. (defcustom gnus-souped-mark ?F
  362.   "*Mark used for killed articles."
  363.   :group 'gnus-summary-marks
  364.   :type 'character)
  365.  
  366. (defcustom gnus-kill-file-mark ?X
  367.   "*Mark used for articles killed by kill files."
  368.   :group 'gnus-summary-marks
  369.   :type 'character)
  370.  
  371. (defcustom gnus-low-score-mark ?Y
  372.   "*Mark used for articles with a low score."
  373.   :group 'gnus-summary-marks
  374.   :type 'character)
  375.  
  376. (defcustom gnus-catchup-mark ?C
  377.   "*Mark used for articles that are caught up."
  378.   :group 'gnus-summary-marks
  379.   :type 'character)
  380.  
  381. (defcustom gnus-replied-mark ?A
  382.   "*Mark used for articles that have been replied to."
  383.   :group 'gnus-summary-marks
  384.   :type 'character)
  385.  
  386. (defcustom gnus-cached-mark ?*
  387.   "*Mark used for articles that are in the cache."
  388.   :group 'gnus-summary-marks
  389.   :type 'character)
  390.  
  391. (defcustom gnus-saved-mark ?S
  392.   "*Mark used for articles that have been saved to."
  393.   :group 'gnus-summary-marks
  394.   :type 'character)
  395.  
  396. (defcustom gnus-ancient-mark ?O
  397.   "*Mark used for ancient articles."
  398.   :group 'gnus-summary-marks
  399.   :type 'character)
  400.  
  401. (defcustom gnus-sparse-mark ?Q
  402.   "*Mark used for sparsely reffed articles."
  403.   :group 'gnus-summary-marks
  404.   :type 'character)
  405.  
  406. (defcustom gnus-canceled-mark ?G
  407.   "*Mark used for canceled articles."
  408.   :group 'gnus-summary-marks
  409.   :type 'character)
  410.  
  411. (defcustom gnus-duplicate-mark ?M
  412.   "*Mark used for duplicate articles."
  413.   :group 'gnus-summary-marks
  414.   :type 'character)
  415.  
  416. (defcustom gnus-score-over-mark ?+
  417.   "*Score mark used for articles with high scores."
  418.   :group 'gnus-summary-marks
  419.   :type 'character)
  420.  
  421. (defcustom gnus-score-below-mark ?-
  422.   "*Score mark used for articles with low scores."
  423.   :group 'gnus-summary-marks
  424.   :type 'character)
  425.  
  426. (defcustom gnus-empty-thread-mark ? 
  427.   "*There is no thread under the article."
  428.   :group 'gnus-summary-marks
  429.   :type 'character)
  430.  
  431. (defcustom gnus-not-empty-thread-mark ?=
  432.   "*There is a thread under the article."
  433.   :group 'gnus-summary-marks
  434.   :type 'character)
  435.  
  436. (defcustom gnus-view-pseudo-asynchronously nil
  437.   "*If non-nil, Gnus will view pseudo-articles asynchronously."
  438.   :group 'gnus-extract-view
  439.   :type 'boolean)
  440.  
  441. (defcustom gnus-view-pseudos nil
  442.   "*If `automatic', pseudo-articles will be viewed automatically.
  443. If `not-confirm', pseudos will be viewed automatically, and the user
  444. will not be asked to confirm the command."
  445.   :group 'gnus-extract-view
  446.   :type '(choice (const :tag "off" nil)
  447.          (const automatic)
  448.          (const not-confirm)))
  449.  
  450. (defcustom gnus-view-pseudos-separately t
  451.   "*If non-nil, one pseudo-article will be created for each file to be viewed.
  452. If nil, all files that use the same viewing command will be given as a
  453. list of parameters to that command."
  454.   :group 'gnus-extract-view
  455.   :type 'boolean)
  456.  
  457. (defcustom gnus-insert-pseudo-articles t
  458.   "*If non-nil, insert pseudo-articles when decoding articles."
  459.   :group 'gnus-extract-view
  460.   :type 'boolean)
  461.  
  462. (defcustom gnus-summary-dummy-line-format
  463.   "*  %(:                          :%) %S\n"
  464.   "*The format specification for the dummy roots in the summary buffer.
  465. It works along the same lines as a normal formatting string,
  466. with some simple extensions.
  467.  
  468. %S  The subject"
  469.   :group 'gnus-threading
  470.   :type 'string)
  471.  
  472. (defcustom gnus-summary-mode-line-format "Gnus: %%b [%A] %Z"
  473.   "*The format specification for the summary mode line.
  474. It works along the same lines as a normal formatting string,
  475. with some simple extensions:
  476.  
  477. %G  Group name
  478. %p  Unprefixed group name
  479. %A  Current article number
  480. %V  Gnus version
  481. %U  Number of unread articles in the group
  482. %e  Number of unselected articles in the group
  483. %Z  A string with unread/unselected article counts
  484. %g  Shortish group name
  485. %S  Subject of the current article
  486. %u  User-defined spec
  487. %s  Current score file name
  488. %d  Number of dormant articles
  489. %r  Number of articles that have been marked as read in this session
  490. %E  Number of articles expunged by the score files"
  491.   :group 'gnus-summary-format
  492.   :type 'string)
  493.  
  494. (defcustom gnus-summary-mark-below 0
  495.   "*Mark all articles with a score below this variable as read.
  496. This variable is local to each summary buffer and usually set by the
  497. score file."
  498.   :group 'gnus-score-default
  499.   :type 'integer)
  500.  
  501. (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
  502.   "*List of functions used for sorting articles in the summary buffer.
  503. This variable is only used when not using a threaded display."
  504.   :group 'gnus-summary-sort
  505.   :type '(repeat (choice (function-item gnus-article-sort-by-number)
  506.              (function-item gnus-article-sort-by-author)
  507.              (function-item gnus-article-sort-by-subject)
  508.              (function-item gnus-article-sort-by-date)
  509.              (function-item gnus-article-sort-by-score)
  510.              (function :tag "other"))))
  511.  
  512. (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
  513.   "*List of functions used for sorting threads in the summary buffer.
  514. By default, threads are sorted by article number.
  515.  
  516. Each function takes two threads and return non-nil if the first thread
  517. should be sorted before the other.  If you use more than one function,
  518. the primary sort function should be the last.  You should probably
  519. always include `gnus-thread-sort-by-number' in the list of sorting
  520. functions -- preferably first.
  521.  
  522. Ready-made functions include `gnus-thread-sort-by-number',
  523. `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
  524. `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
  525. `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
  526.   :group 'gnus-summary-sort
  527.   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
  528.              (function-item gnus-thread-sort-by-author)
  529.              (function-item gnus-thread-sort-by-subject)
  530.              (function-item gnus-thread-sort-by-date)
  531.              (function-item gnus-thread-sort-by-score)
  532.              (function-item gnus-thread-sort-by-total-score)
  533.              (function :tag "other"))))
  534.  
  535. (defcustom gnus-thread-score-function '+
  536.   "*Function used for calculating the total score of a thread.
  537.  
  538. The function is called with the scores of the article and each
  539. subthread and should then return the score of the thread.
  540.  
  541. Some functions you can use are `+', `max', or `min'."
  542.   :group 'gnus-summary-sort
  543.   :type 'function)
  544.  
  545. (defcustom gnus-summary-expunge-below nil
  546.   "All articles that have a score less than this variable will be expunged."
  547.   :group 'gnus-score-default
  548.   :type '(choice (const :tag "off" nil)
  549.          integer))
  550.  
  551. (defcustom gnus-thread-expunge-below nil
  552.   "All threads that have a total score less than this variable will be expunged.
  553. See `gnus-thread-score-function' for en explanation of what a
  554. \"thread score\" is."
  555.   :group 'gnus-treading
  556.   :group 'gnus-score-default
  557.   :type '(choice (const :tag "off" nil)
  558.          integer))
  559.  
  560. (defcustom gnus-summary-mode-hook nil
  561.   "*A hook for Gnus summary mode.
  562. This hook is run before any variables are set in the summary buffer."
  563.   :group 'gnus-summary-various
  564.   :type 'hook)
  565.  
  566. (defcustom gnus-summary-menu-hook nil
  567.   "*Hook run after the creation of the summary mode menu."
  568.   :group 'gnus-summary-visual
  569.   :type 'hook)
  570.  
  571. (defcustom gnus-summary-exit-hook nil
  572.   "*A hook called on exit from the summary buffer.
  573. It will be called with point in the group buffer."
  574.   :group 'gnus-summary-exit
  575.   :type 'hook)
  576.  
  577. (defcustom gnus-summary-prepare-hook nil
  578.   "*A hook called after the summary buffer has been generated.
  579. If you want to modify the summary buffer, you can use this hook."
  580.   :group 'gnus-summary-various
  581.   :type 'hook)
  582.  
  583. (defcustom gnus-summary-generate-hook nil
  584.   "*A hook run just before generating the summary buffer.
  585. This hook is commonly used to customize threading variables and the
  586. like."
  587.   :group 'gnus-summary-various
  588.   :type 'hook)
  589.  
  590. (defcustom gnus-select-group-hook nil
  591.   "*A hook called when a newsgroup is selected.
  592.  
  593. If you'd like to simplify subjects like the
  594. `gnus-summary-next-same-subject' command does, you can use the
  595. following hook:
  596.  
  597.  (setq gnus-select-group-hook
  598.       (list
  599.     (lambda ()
  600.       (mapcar (lambda (header)
  601.              (mail-header-set-subject
  602.               header
  603.               (gnus-simplify-subject
  604.                (mail-header-subject header) 're-only)))
  605.           gnus-newsgroup-headers))))"
  606.   :group 'gnus-group-select
  607.   :type 'hook)
  608.  
  609. (defcustom gnus-select-article-hook nil
  610.   "*A hook called when an article is selected."
  611.   :group 'gnus-summary-choose
  612.   :type 'hook)
  613.  
  614. (defcustom gnus-visual-mark-article-hook
  615.   (list 'gnus-highlight-selected-summary)
  616.   "*Hook run after selecting an article in the summary buffer.
  617. It is meant to be used for highlighting the article in some way.  It
  618. is not run if `gnus-visual' is nil."
  619.   :group 'gnus-summary-visual
  620.   :type 'hook)
  621.  
  622. ;; 1997/5/4 by MORIOKA Tomohiko <morioka@jaist.ac.jp>
  623. (defcustom gnus-structured-field-decoder 'identity
  624.   "Function to decode non-ASCII characters in structured field for summary."
  625.   :group 'gnus-various
  626.   :type 'function)
  627.  
  628. (defcustom gnus-unstructured-field-decoder 'identity
  629.   "Function to decode non-ASCII characters in unstructured field for summary."
  630.   :group 'gnus-various
  631.   :type 'function)
  632.  
  633. (defcustom gnus-parse-headers-hook
  634.   (list 'gnus-hack-decode-rfc1522 'gnus-decode-rfc1522)
  635.   "*A hook called before parsing the headers."
  636.   :group 'gnus-various
  637.   :type 'hook)
  638.  
  639. (defcustom gnus-exit-group-hook nil
  640.   "*A hook called when exiting (not quitting) summary mode."
  641.   :group 'gnus-various
  642.   :type 'hook)
  643.  
  644. (defcustom gnus-summary-update-hook
  645.   (list 'gnus-summary-highlight-line)
  646.   "*A hook called when a summary line is changed.
  647. The hook will not be called if `gnus-visual' is nil.
  648.  
  649. The default function `gnus-summary-highlight-line' will
  650. highlight the line according to the `gnus-summary-highlight'
  651. variable."
  652.   :group 'gnus-summary-visual
  653.   :type 'hook)
  654.  
  655. (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
  656.   "*A hook called when an article is selected for the first time.
  657. The hook is intended to mark an article as read (or unread)
  658. automatically when it is selected."
  659.   :group 'gnus-summary-choose
  660.   :type 'hook)
  661.  
  662. (defcustom gnus-group-no-more-groups-hook nil
  663.   "*A hook run when returning to group mode having no more (unread) groups."
  664.   :group 'gnus-group-select
  665.   :type 'hook)
  666.  
  667. (defcustom gnus-ps-print-hook nil
  668.   "*A hook run before ps-printing something from Gnus."
  669.   :group 'gnus-summary
  670.   :type 'hook)
  671.  
  672. (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
  673.   "Face used for highlighting the current article in the summary buffer."
  674.   :group 'gnus-summary-visual
  675.   :type 'face)
  676.  
  677. (defcustom gnus-summary-highlight
  678.   '(((= mark gnus-canceled-mark)
  679.      . gnus-summary-cancelled-face)
  680.     ((and (> score default)
  681.       (or (= mark gnus-dormant-mark)
  682.           (= mark gnus-ticked-mark)))
  683.      . gnus-summary-high-ticked-face)
  684.     ((and (< score default)
  685.       (or (= mark gnus-dormant-mark)
  686.           (= mark gnus-ticked-mark)))
  687.      . gnus-summary-low-ticked-face)
  688.     ((or (= mark gnus-dormant-mark)
  689.      (= mark gnus-ticked-mark))
  690.      . gnus-summary-normal-ticked-face)
  691.     ((and (> score default) (= mark gnus-ancient-mark))
  692.      . gnus-summary-high-ancient-face)
  693.     ((and (< score default) (= mark gnus-ancient-mark))
  694.      . gnus-summary-low-ancient-face)
  695.     ((= mark gnus-ancient-mark)
  696.      . gnus-summary-normal-ancient-face)
  697.     ((and (> score default) (= mark gnus-unread-mark))
  698.      . gnus-summary-high-unread-face)
  699.     ((and (< score default) (= mark gnus-unread-mark))
  700.      . gnus-summary-low-unread-face)
  701.     ((and (= mark gnus-unread-mark))
  702.      . gnus-summary-normal-unread-face)
  703.     ((> score default)
  704.      . gnus-summary-high-read-face)
  705.     ((< score default)
  706.      . gnus-summary-low-read-face)
  707.     (t
  708.      . gnus-summary-normal-read-face))
  709.   "Controls the highlighting of summary buffer lines.
  710.  
  711. A list of (FORM . FACE) pairs.  When deciding how a a particular
  712. summary line should be displayed, each form is evaluated.  The content
  713. of the face field after the first true form is used.  You can change
  714. how those summary lines are displayed, by editing the face field.
  715.  
  716. You can use the following variables in the FORM field.
  717.  
  718. score:   The articles score
  719. default: The default article score.
  720. below:   The score below which articles are automatically marked as read.
  721. mark:    The articles mark."
  722.   :group 'gnus-summary-visual
  723.   :type '(repeat (cons (sexp :tag "Form" nil)
  724.                face)))
  725.  
  726.  
  727. ;;; Internal variables
  728.  
  729. (defvar gnus-scores-exclude-files nil)
  730. (defvar gnus-page-broken nil)
  731.  
  732. (defvar gnus-original-article nil)
  733. (defvar gnus-article-internal-prepare-hook nil)
  734. (defvar gnus-newsgroup-process-stack nil)
  735.  
  736. (defvar gnus-thread-indent-array nil)
  737. (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
  738.  
  739. ;; Avoid highlighting in kill files.
  740. (defvar gnus-summary-inhibit-highlight nil)
  741. (defvar gnus-newsgroup-selected-overlay nil)
  742. (defvar gnus-inhibit-limiting nil)
  743. (defvar gnus-newsgroup-adaptive-score-file nil)
  744. (defvar gnus-current-score-file nil)
  745. (defvar gnus-current-move-group nil)
  746. (defvar gnus-current-copy-group nil)
  747. (defvar gnus-current-crosspost-group nil)
  748.  
  749. (defvar gnus-newsgroup-dependencies nil)
  750. (defvar gnus-newsgroup-adaptive nil)
  751. (defvar gnus-summary-display-article-function nil)
  752. (defvar gnus-summary-highlight-line-function nil
  753.   "Function called after highlighting a summary line.")
  754.  
  755. (defvar gnus-summary-line-format-alist
  756.   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
  757.     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
  758.     (?s gnus-tmp-subject-or-nil ?s)
  759.     (?n gnus-tmp-name ?s)
  760.     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
  761.     ?s)
  762.     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
  763.         gnus-tmp-from) ?s)
  764.     (?F gnus-tmp-from ?s)
  765.     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
  766.     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
  767.     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
  768.     (?o (gnus-date-iso8601 gnus-tmp-header) ?s)
  769.     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
  770.     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
  771.     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
  772.     (?L gnus-tmp-lines ?d)
  773.     (?I gnus-tmp-indentation ?s)
  774.     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
  775.     (?R gnus-tmp-replied ?c)
  776.     (?\[ gnus-tmp-opening-bracket ?c)
  777.     (?\] gnus-tmp-closing-bracket ?c)
  778.     (?\> (make-string gnus-tmp-level ? ) ?s)
  779.     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
  780.     (?i gnus-tmp-score ?d)
  781.     (?z gnus-tmp-score-char ?c)
  782.     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
  783.     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
  784.     (?U gnus-tmp-unread ?c)
  785.     (?t (gnus-summary-number-of-articles-in-thread
  786.      (and (boundp 'thread) (car thread)) gnus-tmp-level)
  787.     ?d)
  788.     (?e (gnus-summary-number-of-articles-in-thread
  789.      (and (boundp 'thread) (car thread)) gnus-tmp-level t)
  790.     ?c)
  791.     (?u gnus-tmp-user-defined ?s)
  792.     (?P (gnus-pick-line-number) ?d))
  793.   "An alist of format specifications that can appear in summary lines,
  794. and what variables they correspond with, along with the type of the
  795. variable (string, integer, character, etc).")
  796.  
  797. (defvar gnus-summary-dummy-line-format-alist
  798.   `((?S gnus-tmp-subject ?s)
  799.     (?N gnus-tmp-number ?d)
  800.     (?u gnus-tmp-user-defined ?s)))
  801.  
  802. (defvar gnus-summary-mode-line-format-alist
  803.   `((?G gnus-tmp-group-name ?s)
  804.     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
  805.     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
  806.     (?A gnus-tmp-article-number ?d)
  807.     (?Z gnus-tmp-unread-and-unselected ?s)
  808.     (?V gnus-version ?s)
  809.     (?U gnus-tmp-unread-and-unticked ?d)
  810.     (?S gnus-tmp-subject ?s)
  811.     (?e gnus-tmp-unselected ?d)
  812.     (?u gnus-tmp-user-defined ?s)
  813.     (?d (length gnus-newsgroup-dormant) ?d)
  814.     (?t (length gnus-newsgroup-marked) ?d)
  815.     (?r (length gnus-newsgroup-reads) ?d)
  816.     (?E gnus-newsgroup-expunged-tally ?d)
  817.     (?s (gnus-current-score-file-nondirectory) ?s)))
  818.  
  819. (defvar gnus-last-search-regexp nil
  820.   "Default regexp for article search command.")
  821.  
  822. (defvar gnus-last-shell-command nil
  823.   "Default shell command on article.")
  824.  
  825. (defvar gnus-newsgroup-begin nil)
  826. (defvar gnus-newsgroup-end nil)
  827. (defvar gnus-newsgroup-last-rmail nil)
  828. (defvar gnus-newsgroup-last-mail nil)
  829. (defvar gnus-newsgroup-last-folder nil)
  830. (defvar gnus-newsgroup-last-file nil)
  831. (defvar gnus-newsgroup-auto-expire nil)
  832. (defvar gnus-newsgroup-active nil)
  833.  
  834. (defvar gnus-newsgroup-data nil)
  835. (defvar gnus-newsgroup-data-reverse nil)
  836. (defvar gnus-newsgroup-limit nil)
  837. (defvar gnus-newsgroup-limits nil)
  838.  
  839. (defvar gnus-newsgroup-unreads nil
  840.   "List of unread articles in the current newsgroup.")
  841.  
  842. (defvar gnus-newsgroup-unselected nil
  843.   "List of unselected unread articles in the current newsgroup.")
  844.  
  845. (defvar gnus-newsgroup-reads nil
  846.   "Alist of read articles and article marks in the current newsgroup.")
  847.  
  848. (defvar gnus-newsgroup-expunged-tally nil)
  849.  
  850. (defvar gnus-newsgroup-marked nil
  851.   "List of ticked articles in the current newsgroup (a subset of unread art).")
  852.  
  853. (defvar gnus-newsgroup-killed nil
  854.   "List of ranges of articles that have been through the scoring process.")
  855.  
  856. (defvar gnus-newsgroup-cached nil
  857.   "List of articles that come from the article cache.")
  858.  
  859. (defvar gnus-newsgroup-saved nil
  860.   "List of articles that have been saved.")
  861.  
  862. (defvar gnus-newsgroup-kill-headers nil)
  863.  
  864. (defvar gnus-newsgroup-replied nil
  865.   "List of articles that have been replied to in the current newsgroup.")
  866.  
  867. (defvar gnus-newsgroup-expirable nil
  868.   "List of articles in the current newsgroup that can be expired.")
  869.  
  870. (defvar gnus-newsgroup-processable nil
  871.   "List of articles in the current newsgroup that can be processed.")
  872.  
  873. (defvar gnus-newsgroup-bookmarks nil
  874.   "List of articles in the current newsgroup that have bookmarks.")
  875.  
  876. (defvar gnus-newsgroup-dormant nil
  877.   "List of dormant articles in the current newsgroup.")
  878.  
  879. (defvar gnus-newsgroup-scored nil
  880.   "List of scored articles in the current newsgroup.")
  881.  
  882. (defvar gnus-newsgroup-headers nil
  883.   "List of article headers in the current newsgroup.")
  884.  
  885. (defvar gnus-newsgroup-threads nil)
  886.  
  887. (defvar gnus-newsgroup-prepared nil
  888.   "Whether the current group has been prepared properly.")
  889.  
  890. (defvar gnus-newsgroup-ancient nil
  891.   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
  892.  
  893. (defvar gnus-newsgroup-sparse nil)
  894.  
  895. (defvar gnus-current-article nil)
  896. (defvar gnus-article-current nil)
  897. (defvar gnus-current-headers nil)
  898. (defvar gnus-have-all-headers nil)
  899. (defvar gnus-last-article nil)
  900. (defvar gnus-newsgroup-history nil)
  901.  
  902. (defconst gnus-summary-local-variables
  903.   '(gnus-newsgroup-name
  904.     gnus-newsgroup-begin gnus-newsgroup-end
  905.     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
  906.     gnus-newsgroup-last-folder gnus-newsgroup-last-file
  907.     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
  908.     gnus-newsgroup-unselected gnus-newsgroup-marked
  909.     gnus-newsgroup-reads gnus-newsgroup-saved
  910.     gnus-newsgroup-replied gnus-newsgroup-expirable
  911.     gnus-newsgroup-processable gnus-newsgroup-killed
  912.     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
  913.     gnus-newsgroup-headers gnus-newsgroup-threads
  914.     gnus-newsgroup-prepared gnus-summary-highlight-line-function
  915.     gnus-current-article gnus-current-headers gnus-have-all-headers
  916.     gnus-last-article gnus-article-internal-prepare-hook
  917.     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
  918.     gnus-newsgroup-scored gnus-newsgroup-kill-headers
  919.     gnus-thread-expunge-below
  920.     gnus-score-alist gnus-current-score-file gnus-summary-expunge-below
  921.     (gnus-summary-mark-below . global)
  922.     gnus-newsgroup-active gnus-scores-exclude-files
  923.     gnus-newsgroup-history gnus-newsgroup-ancient
  924.     gnus-newsgroup-sparse gnus-newsgroup-process-stack
  925.     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
  926.     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
  927.     (gnus-newsgroup-expunged-tally . 0)
  928.     gnus-cache-removable-articles gnus-newsgroup-cached
  929.     gnus-newsgroup-data gnus-newsgroup-data-reverse
  930.     gnus-newsgroup-limit gnus-newsgroup-limits)
  931.   "Variables that are buffer-local to the summary buffers.")
  932.  
  933. ;; Byte-compiler warning.
  934. (defvar gnus-article-mode-map)
  935.  
  936. ;; Subject simplification.
  937.  
  938. (defsubst gnus-simplify-subject-re (subject)
  939.   "Remove \"Re:\" from subject lines."
  940.   (if (string-match "^[Rr][Ee]: *" subject)
  941.       (substring subject (match-end 0))
  942.     subject))
  943.  
  944. (defun gnus-simplify-subject (subject &optional re-only)
  945.   "Remove `Re:' and words in parentheses.
  946. If RE-ONLY is non-nil, strip leading `Re:'s only."
  947.   (let ((case-fold-search t))        ;Ignore case.
  948.     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
  949.     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
  950.       (setq subject (substring subject (match-end 0))))
  951.     ;; Remove uninteresting prefixes.
  952.     (when (and (not re-only)
  953.            gnus-simplify-ignored-prefixes
  954.            (string-match gnus-simplify-ignored-prefixes subject))
  955.       (setq subject (substring subject (match-end 0))))
  956.     ;; Remove words in parentheses from end.
  957.     (unless re-only
  958.       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
  959.     (setq subject (substring subject 0 (match-beginning 0)))))
  960.     ;; Return subject string.
  961.     subject))
  962.  
  963. ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
  964. ;; all whitespace.
  965. (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
  966.   (goto-char (point-min))
  967.   (while (re-search-forward regexp nil t)
  968.       (replace-match (or newtext ""))))
  969.  
  970. (defun gnus-simplify-buffer-fuzzy ()
  971.   "Simplify string in the buffer fuzzily.
  972. The string in the accessible portion of the current buffer is simplified.
  973. It is assumed to be a single-line subject.
  974. Whitespace is generally cleaned up, and miscellaneous leading/trailing
  975. matter is removed.  Additional things can be deleted by setting
  976. gnus-simplify-subject-fuzzy-regexp."
  977.   (let ((case-fold-search t)
  978.     (modified-tick))
  979.     (gnus-simplify-buffer-fuzzy-step "\t" " ")
  980.  
  981.     (while (not (eq modified-tick (buffer-modified-tick)))
  982.       (setq modified-tick (buffer-modified-tick))
  983.       (cond
  984.        ((listp gnus-simplify-subject-fuzzy-regexp)
  985.     (mapcar 'gnus-simplify-buffer-fuzzy-step
  986.         gnus-simplify-subject-fuzzy-regexp))
  987.        (gnus-simplify-subject-fuzzy-regexp
  988.     (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
  989.       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
  990.       (gnus-simplify-buffer-fuzzy-step
  991.        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
  992.       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
  993.  
  994.     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
  995.     (gnus-simplify-buffer-fuzzy-step "  +" " ")
  996.     (gnus-simplify-buffer-fuzzy-step " $")
  997.     (gnus-simplify-buffer-fuzzy-step "^ +")))
  998.  
  999. (defun gnus-simplify-subject-fuzzy (subject)
  1000.   "Simplify a subject string fuzzily.
  1001. See gnus-simplify-buffer-fuzzy for details."
  1002.   (save-excursion
  1003.     (gnus-set-work-buffer)
  1004.     (let ((case-fold-search t))
  1005.       (insert subject)
  1006.       (inline (gnus-simplify-buffer-fuzzy))
  1007.       (buffer-string))))
  1008.  
  1009. (defsubst gnus-simplify-subject-fully (subject)
  1010.   "Simplify a subject string according to gnus-summary-gather-subject-limit."
  1011.   (cond
  1012.    ((null gnus-summary-gather-subject-limit)
  1013.     (gnus-simplify-subject-re subject))
  1014.    ((eq gnus-summary-gather-subject-limit 'fuzzy)
  1015.     (gnus-simplify-subject-fuzzy subject))
  1016.    ((numberp gnus-summary-gather-subject-limit)
  1017.     (gnus-limit-string (gnus-simplify-subject-re subject)
  1018.                gnus-summary-gather-subject-limit))
  1019.    (t
  1020.     subject)))
  1021.  
  1022. (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
  1023.   "Check whether two subjects are equal.  If optional argument
  1024. simple-first is t, first argument is already simplified."
  1025.   (cond
  1026.    ((null simple-first)
  1027.     (equal (gnus-simplify-subject-fully s1)
  1028.        (gnus-simplify-subject-fully s2)))
  1029.    (t
  1030.     (equal s1
  1031.        (gnus-simplify-subject-fully s2)))))
  1032.  
  1033. (defun gnus-summary-bubble-group ()
  1034.   "Increase the score of the current group.
  1035. This is a handy function to add to `gnus-summary-exit-hook' to
  1036. increase the score of each group you read."
  1037.   (gnus-group-add-score gnus-newsgroup-name))
  1038.  
  1039.  
  1040. ;;;
  1041. ;;; Gnus summary mode
  1042. ;;;
  1043.  
  1044. (put 'gnus-summary-mode 'mode-class 'special)
  1045.  
  1046. (when t
  1047.   ;; Non-orthogonal keys
  1048.  
  1049.   (gnus-define-keys gnus-summary-mode-map
  1050.     " " gnus-summary-next-page
  1051.     "\177" gnus-summary-prev-page
  1052.     [delete] gnus-summary-prev-page
  1053.     [backspace] gnus-summary-prev-page
  1054.     "\r" gnus-summary-scroll-up
  1055.     "n" gnus-summary-next-unread-article
  1056.     "p" gnus-summary-prev-unread-article
  1057.     "N" gnus-summary-next-article
  1058.     "P" gnus-summary-prev-article
  1059.     "\M-\C-n" gnus-summary-next-same-subject
  1060.     "\M-\C-p" gnus-summary-prev-same-subject
  1061.     "\M-n" gnus-summary-next-unread-subject
  1062.     "\M-p" gnus-summary-prev-unread-subject
  1063.     "." gnus-summary-first-unread-article
  1064.     "," gnus-summary-best-unread-article
  1065.     "\M-s" gnus-summary-search-article-forward
  1066.     "\M-r" gnus-summary-search-article-backward
  1067.     "<" gnus-summary-beginning-of-article
  1068.     ">" gnus-summary-end-of-article
  1069.     "j" gnus-summary-goto-article
  1070.     "^" gnus-summary-refer-parent-article
  1071.     "\M-^" gnus-summary-refer-article
  1072.     "u" gnus-summary-tick-article-forward
  1073.     "!" gnus-summary-tick-article-forward
  1074.     "U" gnus-summary-tick-article-backward
  1075.     "d" gnus-summary-mark-as-read-forward
  1076.     "D" gnus-summary-mark-as-read-backward
  1077.     "E" gnus-summary-mark-as-expirable
  1078.     "\M-u" gnus-summary-clear-mark-forward
  1079.     "\M-U" gnus-summary-clear-mark-backward
  1080.     "k" gnus-summary-kill-same-subject-and-select
  1081.     "\C-k" gnus-summary-kill-same-subject
  1082.     "\M-\C-k" gnus-summary-kill-thread
  1083.     "\M-\C-l" gnus-summary-lower-thread
  1084.     "e" gnus-summary-edit-article
  1085.     "#" gnus-summary-mark-as-processable
  1086.     "\M-#" gnus-summary-unmark-as-processable
  1087.     "\M-\C-t" gnus-summary-toggle-threads
  1088.     "\M-\C-s" gnus-summary-show-thread
  1089.     "\M-\C-h" gnus-summary-hide-thread
  1090.     "\M-\C-f" gnus-summary-next-thread
  1091.     "\M-\C-b" gnus-summary-prev-thread
  1092.     "\M-\C-u" gnus-summary-up-thread
  1093.     "\M-\C-d" gnus-summary-down-thread
  1094.     "&" gnus-summary-execute-command
  1095.     "c" gnus-summary-catchup-and-exit
  1096.     "\C-w" gnus-summary-mark-region-as-read
  1097.     "\C-t" gnus-summary-toggle-truncation
  1098.     "?" gnus-summary-mark-as-dormant
  1099.     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
  1100.     "\C-c\C-s\C-n" gnus-summary-sort-by-number
  1101.     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
  1102.     "\C-c\C-s\C-a" gnus-summary-sort-by-author
  1103.     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
  1104.     "\C-c\C-s\C-d" gnus-summary-sort-by-date
  1105.     "\C-c\C-s\C-i" gnus-summary-sort-by-score
  1106.     "=" gnus-summary-expand-window
  1107.     "\C-x\C-s" gnus-summary-reselect-current-group
  1108.     "\M-g" gnus-summary-rescan-group
  1109.     "w" gnus-summary-stop-page-breaking
  1110.     "\C-c\C-r" gnus-summary-caesar-message
  1111.     "\M-t" gnus-summary-toggle-mime
  1112.     "f" gnus-summary-followup
  1113.     "F" gnus-summary-followup-with-original
  1114.     "C" gnus-summary-cancel-article
  1115.     "r" gnus-summary-reply
  1116.     "R" gnus-summary-reply-with-original
  1117.     "\C-c\C-f" gnus-summary-mail-forward
  1118.     "o" gnus-summary-save-article
  1119.     "\C-o" gnus-summary-save-article-mail
  1120.     "|" gnus-summary-pipe-output
  1121.     "\M-k" gnus-summary-edit-local-kill
  1122.     "\M-K" gnus-summary-edit-global-kill
  1123.     ;; "V" gnus-version
  1124.     "\C-c\C-d" gnus-summary-describe-group
  1125.     "q" gnus-summary-exit
  1126.     "Q" gnus-summary-exit-no-update
  1127.     "\C-c\C-i" gnus-info-find-node
  1128.     gnus-mouse-2 gnus-mouse-pick-article
  1129.     "m" gnus-summary-mail-other-window
  1130.     "a" gnus-summary-post-news
  1131.     "x" gnus-summary-limit-to-unread
  1132.     "s" gnus-summary-isearch-article
  1133.     "t" gnus-article-hide-headers
  1134.     "g" gnus-summary-show-article
  1135.     "l" gnus-summary-goto-last-article
  1136.     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
  1137.     "\C-d" gnus-summary-enter-digest-group
  1138.     "\M-\C-d" gnus-summary-read-document
  1139.     "\C-c\C-b" gnus-bug
  1140.     "*" gnus-cache-enter-article
  1141.     "\M-*" gnus-cache-remove-article
  1142.     "\M-&" gnus-summary-universal-argument
  1143.     "\C-l" gnus-recenter
  1144.     "I" gnus-summary-increase-score
  1145.     "L" gnus-summary-lower-score
  1146.  
  1147.     "V" gnus-summary-score-map
  1148.     "X" gnus-uu-extract-map
  1149.     "S" gnus-summary-send-map)
  1150.  
  1151.   ;; Sort of orthogonal keymap
  1152.   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
  1153.     "t" gnus-summary-tick-article-forward
  1154.     "!" gnus-summary-tick-article-forward
  1155.     "d" gnus-summary-mark-as-read-forward
  1156.     "r" gnus-summary-mark-as-read-forward
  1157.     "c" gnus-summary-clear-mark-forward
  1158.     " " gnus-summary-clear-mark-forward
  1159.     "e" gnus-summary-mark-as-expirable
  1160.     "x" gnus-summary-mark-as-expirable
  1161.     "?" gnus-summary-mark-as-dormant
  1162.     "b" gnus-summary-set-bookmark
  1163.     "B" gnus-summary-remove-bookmark
  1164.     "#" gnus-summary-mark-as-processable
  1165.     "\M-#" gnus-summary-unmark-as-processable
  1166.     "S" gnus-summary-limit-include-expunged
  1167.     "C" gnus-summary-catchup
  1168.     "H" gnus-summary-catchup-to-here
  1169.     "\C-c" gnus-summary-catchup-all
  1170.     "k" gnus-summary-kill-same-subject-and-select
  1171.     "K" gnus-summary-kill-same-subject
  1172.     "P" gnus-uu-mark-map)
  1173.  
  1174.   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
  1175.     "c" gnus-summary-clear-above
  1176.     "u" gnus-summary-tick-above
  1177.     "m" gnus-summary-mark-above
  1178.     "k" gnus-summary-kill-below)
  1179.  
  1180.   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
  1181.     "/" gnus-summary-limit-to-subject
  1182.     "n" gnus-summary-limit-to-articles
  1183.     "w" gnus-summary-pop-limit
  1184.     "s" gnus-summary-limit-to-subject
  1185.     "a" gnus-summary-limit-to-author
  1186.     "u" gnus-summary-limit-to-unread
  1187.     "m" gnus-summary-limit-to-marks
  1188.     "v" gnus-summary-limit-to-score
  1189.     "D" gnus-summary-limit-include-dormant
  1190.     "d" gnus-summary-limit-exclude-dormant
  1191.     "t" gnus-summary-limit-to-age
  1192.     "E" gnus-summary-limit-include-expunged
  1193.     "c" gnus-summary-limit-exclude-childless-dormant
  1194.     "C" gnus-summary-limit-mark-excluded-as-read)
  1195.  
  1196.   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
  1197.     "n" gnus-summary-next-unread-article
  1198.     "p" gnus-summary-prev-unread-article
  1199.     "N" gnus-summary-next-article
  1200.     "P" gnus-summary-prev-article
  1201.     "\C-n" gnus-summary-next-same-subject
  1202.     "\C-p" gnus-summary-prev-same-subject
  1203.     "\M-n" gnus-summary-next-unread-subject
  1204.     "\M-p" gnus-summary-prev-unread-subject
  1205.     "f" gnus-summary-first-unread-article
  1206.     "b" gnus-summary-best-unread-article
  1207.     "j" gnus-summary-goto-article
  1208.     "g" gnus-summary-goto-subject
  1209.     "l" gnus-summary-goto-last-article
  1210.     "o" gnus-summary-pop-article)
  1211.  
  1212.   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
  1213.     "k" gnus-summary-kill-thread
  1214.     "l" gnus-summary-lower-thread
  1215.     "i" gnus-summary-raise-thread
  1216.     "T" gnus-summary-toggle-threads
  1217.     "t" gnus-summary-rethread-current
  1218.     "^" gnus-summary-reparent-thread
  1219.     "s" gnus-summary-show-thread
  1220.     "S" gnus-summary-show-all-threads
  1221.     "h" gnus-summary-hide-thread
  1222.     "H" gnus-summary-hide-all-threads
  1223.     "n" gnus-summary-next-thread
  1224.     "p" gnus-summary-prev-thread
  1225.     "u" gnus-summary-up-thread
  1226.     "o" gnus-summary-top-thread
  1227.     "d" gnus-summary-down-thread
  1228.     "#" gnus-uu-mark-thread
  1229.     "\M-#" gnus-uu-unmark-thread)
  1230.  
  1231.   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
  1232.     "g" gnus-summary-prepare
  1233.     "c" gnus-summary-insert-cached-articles)
  1234.  
  1235.   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
  1236.     "c" gnus-summary-catchup-and-exit
  1237.     "C" gnus-summary-catchup-all-and-exit
  1238.     "E" gnus-summary-exit-no-update
  1239.     "Q" gnus-summary-exit
  1240.     "Z" gnus-summary-exit
  1241.     "n" gnus-summary-catchup-and-goto-next-group
  1242.     "R" gnus-summary-reselect-current-group
  1243.     "G" gnus-summary-rescan-group
  1244.     "N" gnus-summary-next-group
  1245.     "s" gnus-summary-save-newsrc
  1246.     "P" gnus-summary-prev-group)
  1247.  
  1248.   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
  1249.     " " gnus-summary-next-page
  1250.     "n" gnus-summary-next-page
  1251.     "\177" gnus-summary-prev-page
  1252.     [delete] gnus-summary-prev-page
  1253.     "p" gnus-summary-prev-page
  1254.     "\r" gnus-summary-scroll-up
  1255.     "<" gnus-summary-beginning-of-article
  1256.     ">" gnus-summary-end-of-article
  1257.     "b" gnus-summary-beginning-of-article
  1258.     "e" gnus-summary-end-of-article
  1259.     "^" gnus-summary-refer-parent-article
  1260.     "r" gnus-summary-refer-parent-article
  1261.     "R" gnus-summary-refer-references
  1262.     "g" gnus-summary-show-article
  1263.     "s" gnus-summary-isearch-article
  1264.     "P" gnus-summary-print-article)
  1265.  
  1266.   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
  1267.     "b" gnus-article-add-buttons
  1268.     "B" gnus-article-add-buttons-to-head
  1269.     "o" gnus-article-treat-overstrike
  1270.     "e" gnus-article-emphasize
  1271.     "w" gnus-article-fill-cited-article
  1272.     "c" gnus-article-remove-cr
  1273.     "q" gnus-article-de-quoted-unreadable
  1274.     "f" gnus-article-display-x-face
  1275.     "l" gnus-summary-stop-page-breaking
  1276.     "r" gnus-summary-caesar-message
  1277.     "t" gnus-article-hide-headers
  1278.     "v" gnus-summary-verbose-headers
  1279.     "m" gnus-summary-toggle-mime
  1280.     "h" gnus-article-treat-html)
  1281.  
  1282.   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
  1283.     "a" gnus-article-hide
  1284.     "h" gnus-article-hide-headers
  1285.     "b" gnus-article-hide-boring-headers
  1286.     "s" gnus-article-hide-signature
  1287.     "c" gnus-article-hide-citation
  1288.     "p" gnus-article-hide-pgp
  1289.     "P" gnus-article-hide-pem
  1290.     "\C-c" gnus-article-hide-citation-maybe)
  1291.  
  1292.   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
  1293.     "a" gnus-article-highlight
  1294.     "h" gnus-article-highlight-headers
  1295.     "c" gnus-article-highlight-citation
  1296.     "s" gnus-article-highlight-signature)
  1297.  
  1298.   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
  1299.     "z" gnus-article-date-ut
  1300.     "u" gnus-article-date-ut
  1301.     "l" gnus-article-date-local
  1302.     "e" gnus-article-date-lapsed
  1303.     "o" gnus-article-date-original
  1304.     "s" gnus-article-date-user)
  1305.  
  1306.   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
  1307.     "t" gnus-article-remove-trailing-blank-lines
  1308.     "l" gnus-article-strip-leading-blank-lines
  1309.     "m" gnus-article-strip-multiple-blank-lines
  1310.     "a" gnus-article-strip-blank-lines
  1311.     "s" gnus-article-strip-leading-space)
  1312.  
  1313.   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
  1314.     "v" gnus-version
  1315.     "f" gnus-summary-fetch-faq
  1316.     "d" gnus-summary-describe-group
  1317.     "h" gnus-summary-describe-briefly
  1318.     "i" gnus-info-find-node)
  1319.  
  1320.   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
  1321.     "e" gnus-summary-expire-articles
  1322.     "\M-\C-e" gnus-summary-expire-articles-now
  1323.     "\177" gnus-summary-delete-article
  1324.     [delete] gnus-summary-delete-article
  1325.     "m" gnus-summary-move-article
  1326.     "r" gnus-summary-respool-article
  1327.     "w" gnus-summary-edit-article
  1328.     "c" gnus-summary-copy-article
  1329.     "B" gnus-summary-crosspost-article
  1330.     "q" gnus-summary-respool-query
  1331.     "i" gnus-summary-import-article
  1332.     "p" gnus-summary-article-posted-p)
  1333.  
  1334.   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
  1335.     "o" gnus-summary-save-article
  1336.     "m" gnus-summary-save-article-mail
  1337.     "F" gnus-summary-write-article-file
  1338.     "r" gnus-summary-save-article-rmail
  1339.     "f" gnus-summary-save-article-file
  1340.     "b" gnus-summary-save-article-body-file
  1341.     "h" gnus-summary-save-article-folder
  1342.     "v" gnus-summary-save-article-vm
  1343.     "p" gnus-summary-pipe-output
  1344.     "s" gnus-soup-add-article))
  1345.  
  1346. (defun gnus-summary-make-menu-bar ()
  1347.   (gnus-turn-off-edit-menu 'summary)
  1348.  
  1349.   (unless (boundp 'gnus-summary-misc-menu)
  1350.  
  1351.     (easy-menu-define
  1352.      gnus-summary-kill-menu gnus-summary-mode-map ""
  1353.      (cons
  1354.       "Score"
  1355.       (nconc
  1356.        (list
  1357.     ["Enter score..." gnus-summary-score-entry t]
  1358.     ["Customize" gnus-score-customize t])
  1359.        (gnus-make-score-map 'increase)
  1360.        (gnus-make-score-map 'lower)
  1361.        '(("Mark"
  1362.       ["Kill below" gnus-summary-kill-below t]
  1363.       ["Mark above" gnus-summary-mark-above t]
  1364.       ["Tick above" gnus-summary-tick-above t]
  1365.       ["Clear above" gnus-summary-clear-above t])
  1366.      ["Current score" gnus-summary-current-score t]
  1367.      ["Set score" gnus-summary-set-score t]
  1368.      ["Switch current score file..." gnus-score-change-score-file t]
  1369.      ["Set mark below..." gnus-score-set-mark-below t]
  1370.      ["Set expunge below..." gnus-score-set-expunge-below t]
  1371.      ["Edit current score file" gnus-score-edit-current-scores t]
  1372.      ["Edit score file" gnus-score-edit-file t]
  1373.      ["Trace score" gnus-score-find-trace t]
  1374.      ["Find words" gnus-score-find-favourite-words t]
  1375.      ["Rescore buffer" gnus-summary-rescore t]
  1376.      ["Increase score..." gnus-summary-increase-score t]
  1377.      ["Lower score..." gnus-summary-lower-score t]))))
  1378.  
  1379.     '(("Default header"
  1380.        ["Ask" (gnus-score-set-default 'gnus-score-default-header nil)
  1381.     :style radio
  1382.     :selected (null gnus-score-default-header)]
  1383.        ["From" (gnus-score-set-default 'gnus-score-default-header 'a)
  1384.     :style radio
  1385.     :selected (eq gnus-score-default-header 'a)]
  1386.        ["Subject" (gnus-score-set-default 'gnus-score-default-header 's)
  1387.     :style radio
  1388.     :selected (eq gnus-score-default-header 's)]
  1389.        ["Article body"
  1390.     (gnus-score-set-default 'gnus-score-default-header 'b)
  1391.     :style radio
  1392.     :selected (eq gnus-score-default-header 'b )]
  1393.        ["All headers"
  1394.     (gnus-score-set-default 'gnus-score-default-header 'h)
  1395.     :style radio
  1396.     :selected (eq gnus-score-default-header 'h )]
  1397.        ["Message-ID" (gnus-score-set-default 'gnus-score-default-header 'i)
  1398.     :style radio
  1399.     :selected (eq gnus-score-default-header 'i )]
  1400.        ["Thread" (gnus-score-set-default 'gnus-score-default-header 't)
  1401.     :style radio
  1402.     :selected (eq gnus-score-default-header 't )]
  1403.        ["Crossposting"
  1404.     (gnus-score-set-default 'gnus-score-default-header 'x)
  1405.     :style radio
  1406.     :selected (eq gnus-score-default-header 'x )]
  1407.        ["Lines" (gnus-score-set-default 'gnus-score-default-header 'l)
  1408.     :style radio
  1409.     :selected (eq gnus-score-default-header 'l )]
  1410.        ["Date" (gnus-score-set-default 'gnus-score-default-header 'd)
  1411.     :style radio
  1412.     :selected (eq gnus-score-default-header 'd )]
  1413.        ["Followups to author"
  1414.     (gnus-score-set-default 'gnus-score-default-header 'f)
  1415.     :style radio
  1416.     :selected (eq gnus-score-default-header 'f )])
  1417.       ("Default type"
  1418.        ["Ask" (gnus-score-set-default 'gnus-score-default-type nil)
  1419.     :style radio
  1420.     :selected (null gnus-score-default-type)]
  1421.        ;; The `:active' key is commented out in the following,
  1422.        ;; because the GNU Emacs hack to support radio buttons use
  1423.        ;; active to indicate which button is selected.
  1424.        ["Substring" (gnus-score-set-default 'gnus-score-default-type 's)
  1425.     :style radio
  1426.     ;; :active (not (memq gnus-score-default-header '(l d)))
  1427.     :selected (eq gnus-score-default-type 's)]
  1428.        ["Regexp" (gnus-score-set-default 'gnus-score-default-type 'r)
  1429.     :style radio
  1430.     ;; :active (not (memq gnus-score-default-header '(l d)))
  1431.     :selected (eq gnus-score-default-type 'r)]
  1432.        ["Exact" (gnus-score-set-default 'gnus-score-default-type 'e)
  1433.     :style radio
  1434.     ;; :active (not (memq gnus-score-default-header '(l d)))
  1435.     :selected (eq gnus-score-default-type 'e)]
  1436.        ["Fuzzy" (gnus-score-set-default 'gnus-score-default-type 'f)
  1437.     :style radio
  1438.     ;; :active (not (memq gnus-score-default-header '(l d)))
  1439.     :selected (eq gnus-score-default-type 'f)]
  1440.        ["Before date" (gnus-score-set-default 'gnus-score-default-type 'b)
  1441.     :style radio
  1442.     ;; :active (eq (gnus-score-default-header 'd))
  1443.     :selected (eq gnus-score-default-type 'b)]
  1444.        ["At date" (gnus-score-set-default 'gnus-score-default-type 'n)
  1445.     :style radio
  1446.     ;; :active (eq (gnus-score-default-header 'd))
  1447.     :selected (eq gnus-score-default-type 'n)]
  1448.        ["After date" (gnus-score-set-default 'gnus-score-default-type 'a)
  1449.     :style radio
  1450.     ;; :active (eq (gnus-score-default-header 'd))
  1451.     :selected (eq gnus-score-default-type 'a)]
  1452.        ["Less than number"
  1453.     (gnus-score-set-default 'gnus-score-default-type '<)
  1454.     :style radio
  1455.     ;; :active (eq (gnus-score-default-header 'l))
  1456.     :selected (eq gnus-score-default-type '<)]
  1457.        ["Equal to number"
  1458.     (gnus-score-set-default 'gnus-score-default-type '=)
  1459.     :style radio
  1460.     ;; :active (eq (gnus-score-default-header 'l))
  1461.     :selected (eq gnus-score-default-type '=)]
  1462.        ["Greater than number"
  1463.     (gnus-score-set-default 'gnus-score-default-type '>)
  1464.     :style radio
  1465.     ;; :active (eq (gnus-score-default-header 'l))
  1466.     :selected (eq gnus-score-default-type '>)])
  1467.       ["Default fold" gnus-score-default-fold-toggle
  1468.        :style toggle
  1469.        :selected gnus-score-default-fold]
  1470.       ("Default duration"
  1471.        ["Ask" (gnus-score-set-default 'gnus-score-default-duration nil)
  1472.     :style radio
  1473.     :selected (null gnus-score-default-duration)]
  1474.        ["Permanent"
  1475.     (gnus-score-set-default 'gnus-score-default-duration 'p)
  1476.     :style radio
  1477.     :selected (eq gnus-score-default-duration 'p)]
  1478.        ["Temporary"
  1479.     (gnus-score-set-default 'gnus-score-default-duration 't)
  1480.     :style radio
  1481.     :selected (eq gnus-score-default-duration 't)]
  1482.        ["Immediate"
  1483.     (gnus-score-set-default 'gnus-score-default-duration 'i)
  1484.     :style radio
  1485.     :selected (eq gnus-score-default-duration 'i)]))
  1486.  
  1487.     (easy-menu-define
  1488.      gnus-summary-article-menu gnus-summary-mode-map ""
  1489.      '("Article"
  1490.        ("Hide"
  1491.     ["All" gnus-article-hide t]
  1492.     ["Headers" gnus-article-hide-headers t]
  1493.     ["Signature" gnus-article-hide-signature t]
  1494.     ["Citation" gnus-article-hide-citation t]
  1495.     ["PGP" gnus-article-hide-pgp t]
  1496.     ["Boring headers" gnus-article-hide-boring-headers t])
  1497.        ("Highlight"
  1498.     ["All" gnus-article-highlight t]
  1499.     ["Headers" gnus-article-highlight-headers t]
  1500.     ["Signature" gnus-article-highlight-signature t]
  1501.     ["Citation" gnus-article-highlight-citation t])
  1502.        ("Date"
  1503.     ["Local" gnus-article-date-local t]
  1504.     ["UT" gnus-article-date-ut t]
  1505.     ["Original" gnus-article-date-original t]
  1506.     ["Lapsed" gnus-article-date-lapsed t]
  1507.     ["User-defined" gnus-article-date-user t])
  1508.        ("Washing"
  1509.     ("Remove Blanks"
  1510.      ["Leading" gnus-article-strip-leading-blank-lines t]
  1511.      ["Multiple" gnus-article-strip-multiple-blank-lines t]
  1512.      ["Trailing" gnus-article-remove-trailing-blank-lines t]
  1513.      ["All of the above" gnus-article-strip-blank-lines t]
  1514.      ["Leading space" gnus-article-strip-leading-space t])
  1515.     ["Overstrike" gnus-article-treat-overstrike t]
  1516.     ["Emphasis" gnus-article-emphasize t]
  1517.     ["Word wrap" gnus-article-fill-cited-article t]
  1518.     ["CR" gnus-article-remove-cr t]
  1519.     ["Show X-Face" gnus-article-display-x-face t]
  1520.     ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
  1521.     ["UnHTMLize" gnus-article-treat-html t]
  1522.     ["Rot 13" gnus-summary-caesar-message t]
  1523.     ["Unix pipe" gnus-summary-pipe-message t]
  1524.     ["Add buttons" gnus-article-add-buttons t]
  1525.     ["Add buttons to head" gnus-article-add-buttons-to-head t]
  1526.     ["Stop page breaking" gnus-summary-stop-page-breaking t]
  1527.     ["Toggle MIME" gnus-summary-toggle-mime t]
  1528.     ["Verbose header" gnus-summary-verbose-headers t]
  1529.     ["Toggle header" gnus-summary-toggle-header t])
  1530.        ("Output"
  1531.     ["Save in default format" gnus-summary-save-article t]
  1532.     ["Save in file" gnus-summary-save-article-file t]
  1533.     ["Save in Unix mail format" gnus-summary-save-article-mail t]
  1534.     ["Write to file" gnus-summary-write-article-mail t]
  1535.     ["Save in MH folder" gnus-summary-save-article-folder t]
  1536.     ["Save in VM folder" gnus-summary-save-article-vm t]
  1537.     ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
  1538.     ["Save body in file" gnus-summary-save-article-body-file t]
  1539.     ["Pipe through a filter" gnus-summary-pipe-output t]
  1540.     ["Add to SOUP packet" gnus-soup-add-article t]
  1541.     ["Print" gnus-summary-print-article t])
  1542.        ("Backend"
  1543.     ["Respool article..." gnus-summary-respool-article t]
  1544.     ["Move article..." gnus-summary-move-article
  1545.      (gnus-check-backend-function
  1546.       'request-move-article gnus-newsgroup-name)]
  1547.     ["Copy article..." gnus-summary-copy-article t]
  1548.     ["Crosspost article..." gnus-summary-crosspost-article
  1549.      (gnus-check-backend-function
  1550.       'request-replace-article gnus-newsgroup-name)]
  1551.     ["Import file..." gnus-summary-import-article t]
  1552.     ["Check if posted" gnus-summary-article-posted-p t]
  1553.     ["Edit article" gnus-summary-edit-article
  1554.      (not (gnus-group-read-only-p))]
  1555.     ["Delete article" gnus-summary-delete-article
  1556.      (gnus-check-backend-function
  1557.       'request-expire-articles gnus-newsgroup-name)]
  1558.     ["Query respool" gnus-summary-respool-query t]
  1559.     ["Delete expirable articles" gnus-summary-expire-articles-now
  1560.      (gnus-check-backend-function
  1561.       'request-expire-articles gnus-newsgroup-name)])
  1562.        ("Extract"
  1563.     ["Uudecode" gnus-uu-decode-uu t]
  1564.     ["Uudecode and save" gnus-uu-decode-uu-and-save t]
  1565.     ["Unshar" gnus-uu-decode-unshar t]
  1566.     ["Unshar and save" gnus-uu-decode-unshar-and-save t]
  1567.     ["Save" gnus-uu-decode-save t]
  1568.     ["Binhex" gnus-uu-decode-binhex t]
  1569.     ["Postscript" gnus-uu-decode-postscript t])
  1570.        ("Cache"
  1571.     ["Enter article" gnus-cache-enter-article t]
  1572.     ["Remove article" gnus-cache-remove-article t])
  1573.        ["Enter digest buffer" gnus-summary-enter-digest-group t]
  1574.        ["Isearch article..." gnus-summary-isearch-article t]
  1575.        ["Beginning of the article" gnus-summary-beginning-of-article t]
  1576.        ["End of the article" gnus-summary-end-of-article t]
  1577.        ["Fetch parent of article" gnus-summary-refer-parent-article t]
  1578.        ["Fetch referenced articles" gnus-summary-refer-references t]
  1579.        ["Fetch article with id..." gnus-summary-refer-article t]
  1580.        ["Redisplay" gnus-summary-show-article t]))
  1581.  
  1582.     (easy-menu-define
  1583.      gnus-summary-thread-menu gnus-summary-mode-map ""
  1584.      '("Threads"
  1585.        ["Toggle threading" gnus-summary-toggle-threads t]
  1586.        ["Hide threads" gnus-summary-hide-all-threads t]
  1587.        ["Show threads" gnus-summary-show-all-threads t]
  1588.        ["Hide thread" gnus-summary-hide-thread t]
  1589.        ["Show thread" gnus-summary-show-thread t]
  1590.        ["Go to next thread" gnus-summary-next-thread t]
  1591.        ["Go to previous thread" gnus-summary-prev-thread t]
  1592.        ["Go down thread" gnus-summary-down-thread t]
  1593.        ["Go up thread" gnus-summary-up-thread t]
  1594.        ["Top of thread" gnus-summary-top-thread t]
  1595.        ["Mark thread as read" gnus-summary-kill-thread t]
  1596.        ["Lower thread score" gnus-summary-lower-thread t]
  1597.        ["Raise thread score" gnus-summary-raise-thread t]
  1598.        ["Rethread current" gnus-summary-rethread-current t]
  1599.        ))
  1600.  
  1601.     (easy-menu-define
  1602.      gnus-summary-post-menu gnus-summary-mode-map ""
  1603.      '("Post"
  1604.        ["Post an article" gnus-summary-post-news t]
  1605.        ["Followup" gnus-summary-followup t]
  1606.        ["Followup and yank" gnus-summary-followup-with-original t]
  1607.        ["Supersede article" gnus-summary-supersede-article t]
  1608.        ["Cancel article" gnus-summary-cancel-article t]
  1609.        ["Reply" gnus-summary-reply t]
  1610.        ["Reply and yank" gnus-summary-reply-with-original t]
  1611.        ["Wide reply" gnus-summary-wide-reply t]
  1612.        ["Wide reply and yank" gnus-summary-wide-reply-with-original t]
  1613.        ["Mail forward" gnus-summary-mail-forward t]
  1614.        ["Post forward" gnus-summary-post-forward t]
  1615.        ["Digest and mail" gnus-uu-digest-mail-forward t]
  1616.        ["Digest and post" gnus-uu-digest-post-forward t]
  1617.        ["Resend message" gnus-summary-resend-message t]
  1618.        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
  1619.        ["Send a mail" gnus-summary-mail-other-window t]
  1620.        ["Uuencode and post" gnus-uu-post-news t]
  1621.        ["Followup via news" gnus-summary-followup-to-mail t]
  1622.        ["Followup via news and yank"
  1623.     gnus-summary-followup-to-mail-with-original t]
  1624.        ;;("Draft"
  1625.        ;;["Send" gnus-summary-send-draft t]
  1626.        ;;["Send bounced" gnus-resend-bounced-mail t])
  1627.        ))
  1628.  
  1629.     (easy-menu-define
  1630.      gnus-summary-misc-menu gnus-summary-mode-map ""
  1631.      '("Misc"
  1632.        ("Mark Read"
  1633.     ["Mark as read" gnus-summary-mark-as-read-forward t]
  1634.     ["Mark same subject and select"
  1635.      gnus-summary-kill-same-subject-and-select t]
  1636.     ["Mark same subject" gnus-summary-kill-same-subject t]
  1637.     ["Catchup" gnus-summary-catchup t]
  1638.     ["Catchup all" gnus-summary-catchup-all t]
  1639.     ["Catchup to here" gnus-summary-catchup-to-here t]
  1640.     ["Catchup region" gnus-summary-mark-region-as-read t]
  1641.     ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
  1642.        ("Mark Various"
  1643.     ["Tick" gnus-summary-tick-article-forward t]
  1644.     ["Mark as dormant" gnus-summary-mark-as-dormant t]
  1645.     ["Remove marks" gnus-summary-clear-mark-forward t]
  1646.     ["Set expirable mark" gnus-summary-mark-as-expirable t]
  1647.     ["Set bookmark" gnus-summary-set-bookmark t]
  1648.     ["Remove bookmark" gnus-summary-remove-bookmark t])
  1649.        ("Mark Limit"
  1650.     ["Marks..." gnus-summary-limit-to-marks t]
  1651.     ["Subject..." gnus-summary-limit-to-subject t]
  1652.     ["Author..." gnus-summary-limit-to-author t]
  1653.     ["Age..." gnus-summary-limit-to-age t]
  1654.     ["Score" gnus-summary-limit-to-score t]
  1655.     ["Unread" gnus-summary-limit-to-unread t]
  1656.     ["Non-dormant" gnus-summary-limit-exclude-dormant t]
  1657.     ["Articles" gnus-summary-limit-to-articles t]
  1658.     ["Pop limit" gnus-summary-pop-limit t]
  1659.     ["Show dormant" gnus-summary-limit-include-dormant t]
  1660.     ["Hide childless dormant"
  1661.      gnus-summary-limit-exclude-childless-dormant t]
  1662.     ;;["Hide thread" gnus-summary-limit-exclude-thread t]
  1663.     ["Show expunged" gnus-summary-show-all-expunged t])
  1664.        ("Process Mark"
  1665.     ["Set mark" gnus-summary-mark-as-processable t]
  1666.     ["Remove mark" gnus-summary-unmark-as-processable t]
  1667.     ["Remove all marks" gnus-summary-unmark-all-processable t]
  1668.     ["Mark above" gnus-uu-mark-over t]
  1669.     ["Mark series" gnus-uu-mark-series t]
  1670.     ["Mark region" gnus-uu-mark-region t]
  1671.     ["Mark by regexp..." gnus-uu-mark-by-regexp t]
  1672.     ["Mark all" gnus-uu-mark-all t]
  1673.     ["Mark buffer" gnus-uu-mark-buffer t]
  1674.     ["Mark sparse" gnus-uu-mark-sparse t]
  1675.     ["Mark thread" gnus-uu-mark-thread t]
  1676.     ["Unmark thread" gnus-uu-unmark-thread t]
  1677.     ("Process Mark Sets"
  1678.      ["Kill" gnus-summary-kill-process-mark t]
  1679.      ["Yank" gnus-summary-yank-process-mark
  1680.       gnus-newsgroup-process-stack]
  1681.      ["Save" gnus-summary-save-process-mark t]))
  1682.        ("Scroll article"
  1683.     ["Page forward" gnus-summary-next-page t]
  1684.     ["Page backward" gnus-summary-prev-page t]
  1685.     ["Line forward" gnus-summary-scroll-up t])
  1686.        ("Move"
  1687.     ["Next unread article" gnus-summary-next-unread-article t]
  1688.     ["Previous unread article" gnus-summary-prev-unread-article t]
  1689.     ["Next article" gnus-summary-next-article t]
  1690.     ["Previous article" gnus-summary-prev-article t]
  1691.     ["Next unread subject" gnus-summary-next-unread-subject t]
  1692.     ["Previous unread subject" gnus-summary-prev-unread-subject t]
  1693.     ["Next article same subject" gnus-summary-next-same-subject t]
  1694.     ["Previous article same subject" gnus-summary-prev-same-subject t]
  1695.     ["First unread article" gnus-summary-first-unread-article t]
  1696.     ["Best unread article" gnus-summary-best-unread-article t]
  1697.     ["Go to subject number..." gnus-summary-goto-subject t]
  1698.     ["Go to article number..." gnus-summary-goto-article t]
  1699.     ["Go to the last article" gnus-summary-goto-last-article t]
  1700.     ["Pop article off history" gnus-summary-pop-article t])
  1701.        ("Sort"
  1702.     ["Sort by number" gnus-summary-sort-by-number t]
  1703.     ["Sort by author" gnus-summary-sort-by-author t]
  1704.     ["Sort by subject" gnus-summary-sort-by-subject t]
  1705.     ["Sort by date" gnus-summary-sort-by-date t]
  1706.     ["Sort by score" gnus-summary-sort-by-score t]
  1707.     ["Sort by lines" gnus-summary-sort-by-lines t])
  1708.        ("Help"
  1709.     ["Fetch group FAQ" gnus-summary-fetch-faq t]
  1710.     ["Describe group" gnus-summary-describe-group t]
  1711.     ["Read manual" gnus-info-find-node t])
  1712.        ("Modes"
  1713.     ["Pick and read" gnus-pick-mode t]
  1714.     ["Binary" gnus-binary-mode t])
  1715.        ("Regeneration"
  1716.     ["Regenerate" gnus-summary-prepare t]
  1717.     ["Insert cached articles" gnus-summary-insert-cached-articles t]
  1718.     ["Toggle threading" gnus-summary-toggle-threads t])
  1719.        ["Filter articles..." gnus-summary-execute-command t]
  1720.        ["Run command on subjects..." gnus-summary-universal-argument t]
  1721.        ["Search articles forward..." gnus-summary-search-article-forward t]
  1722.        ["Search articles backward..." gnus-summary-search-article-backward t]
  1723.        ["Toggle line truncation" gnus-summary-toggle-truncation t]
  1724.        ["Expand window" gnus-summary-expand-window t]
  1725.        ["Expire expirable articles" gnus-summary-expire-articles
  1726.     (gnus-check-backend-function
  1727.      'request-expire-articles gnus-newsgroup-name)]
  1728.        ["Edit local kill file" gnus-summary-edit-local-kill t]
  1729.        ["Edit main kill file" gnus-summary-edit-global-kill t]
  1730.        ("Exit"
  1731.     ["Catchup and exit" gnus-summary-catchup-and-exit t]
  1732.     ["Catchup all and exit" gnus-summary-catchup-and-exit t]
  1733.     ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
  1734.     ["Exit group" gnus-summary-exit t]
  1735.     ["Exit group without updating" gnus-summary-exit-no-update t]
  1736.     ["Exit and goto next group" gnus-summary-next-group t]
  1737.     ["Exit and goto prev group" gnus-summary-prev-group t]
  1738.     ["Reselect group" gnus-summary-reselect-current-group t]
  1739.     ["Rescan group" gnus-summary-rescan-group t]
  1740.     ["Update dribble" gnus-summary-save-newsrc t])))
  1741.  
  1742.     (run-hooks 'gnus-summary-menu-hook)))
  1743.  
  1744. (defun gnus-score-set-default (var value)
  1745.   "A version of set that updates the GNU Emacs menu-bar."
  1746.   (set var value)
  1747.   ;; It is the message that forces the active status to be updated.
  1748.   (message ""))
  1749.  
  1750. (defun gnus-make-score-map (type)
  1751.   "Make a summary score map of type TYPE."
  1752.   (if t
  1753.       nil
  1754.     (let ((headers '(("author" "from" string)
  1755.              ("subject" "subject" string)
  1756.              ("article body" "body" string)
  1757.              ("article head" "head" string)
  1758.              ("xref" "xref" string)
  1759.              ("lines" "lines" number)
  1760.              ("followups to author" "followup" string)))
  1761.       (types '((number ("less than" <)
  1762.                ("greater than" >)
  1763.                ("equal" =))
  1764.            (string ("substring" s)
  1765.                ("exact string" e)
  1766.                ("fuzzy string" f)
  1767.                ("regexp" r))))
  1768.       (perms '(("temporary" (current-time-string))
  1769.            ("permanent" nil)
  1770.            ("immediate" now)))
  1771.       header)
  1772.       (list
  1773.        (apply
  1774.     'nconc
  1775.     (list
  1776.      (if (eq type 'lower)
  1777.          "Lower score"
  1778.        "Increase score"))
  1779.     (let (outh)
  1780.       (while headers
  1781.         (setq header (car headers))
  1782.         (setq outh
  1783.           (cons
  1784.            (apply
  1785.             'nconc
  1786.             (list (car header))
  1787.             (let ((ts (cdr (assoc (nth 2 header) types)))
  1788.               outt)
  1789.               (while ts
  1790.             (setq outt
  1791.                   (cons
  1792.                    (apply
  1793.                 'nconc
  1794.                 (list (caar ts))
  1795.                 (let ((ps perms)
  1796.                       outp)
  1797.                   (while ps
  1798.                     (setq outp
  1799.                       (cons
  1800.                        (vector
  1801.                         (caar ps)
  1802.                         (list
  1803.                          'gnus-summary-score-entry
  1804.                          (nth 1 header)
  1805.                          (if (or (string= (nth 1 header)
  1806.                                   "head")
  1807.                              (string= (nth 1 header)
  1808.                                   "body"))
  1809.                          ""
  1810.                            (list 'gnus-summary-header
  1811.                              (nth 1 header)))
  1812.                          (list 'quote (nth 1 (car ts)))
  1813.                          (list 'gnus-score-default nil)
  1814.                          (nth 1 (car ps))
  1815.                          t)
  1816.                         t)
  1817.                        outp))
  1818.                     (setq ps (cdr ps)))
  1819.                   (list (nreverse outp))))
  1820.                    outt))
  1821.             (setq ts (cdr ts)))
  1822.               (list (nreverse outt))))
  1823.            outh))
  1824.         (setq headers (cdr headers)))
  1825.       (list (nreverse outh))))))))
  1826.  
  1827.  
  1828.  
  1829. (defun gnus-summary-mode (&optional group)
  1830.   "Major mode for reading articles.
  1831.  
  1832. All normal editing commands are switched off.
  1833. \\<gnus-summary-mode-map>
  1834. Each line in this buffer represents one article.  To read an
  1835. article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
  1836. and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
  1837. respectively.
  1838.  
  1839. You can also post articles and send mail from this buffer.  To
  1840. follow up an article, type `\\[gnus-summary-followup]'.     To mail a reply to the author
  1841. of an article, type `\\[gnus-summary-reply]'.
  1842.  
  1843. There are approx. one gazillion commands you can execute in this
  1844. buffer; read the info pages for more information (`\\[gnus-info-find-node]').
  1845.  
  1846. The following commands are available:
  1847.  
  1848. \\{gnus-summary-mode-map}"
  1849.   (interactive)
  1850.   (when (gnus-visual-p 'summary-menu 'menu)
  1851.     (gnus-summary-make-menu-bar))
  1852.   (kill-all-local-variables)
  1853.   (gnus-summary-make-local-variables)
  1854.   (gnus-make-thread-indent-array)
  1855.   (gnus-simplify-mode-line)
  1856.   (setq major-mode 'gnus-summary-mode)
  1857.   (setq mode-name "Summary")
  1858.   (make-local-variable 'minor-mode-alist)
  1859.   (use-local-map gnus-summary-mode-map)
  1860.   (buffer-disable-undo (current-buffer))
  1861.   (setq buffer-read-only t)        ;Disable modification
  1862.   (setq truncate-lines t)
  1863.   (setq selective-display t)
  1864.   (setq selective-display-ellipses t)    ;Display `...'
  1865.   (gnus-summary-set-display-table)
  1866.   (gnus-set-default-directory)
  1867.   (setq gnus-newsgroup-name group)
  1868.   (make-local-variable 'gnus-summary-line-format)
  1869.   (make-local-variable 'gnus-summary-line-format-spec)
  1870.   (make-local-variable 'gnus-summary-mark-positions)
  1871.   (make-local-hook 'post-command-hook)
  1872.   (add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
  1873.   (run-hooks 'gnus-summary-mode-hook)
  1874.   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
  1875.   (gnus-update-summary-mark-positions))
  1876.  
  1877. (defun gnus-summary-make-local-variables ()
  1878.   "Make all the local summary buffer variables."
  1879.   (let ((locals gnus-summary-local-variables)
  1880.     global local)
  1881.     (while (setq local (pop locals))
  1882.       (if (consp local)
  1883.       (progn
  1884.         (if (eq (cdr local) 'global)
  1885.         ;; Copy the global value of the variable.
  1886.         (setq global (symbol-value (car local)))
  1887.           ;; Use the value from the list.
  1888.           (setq global (eval (cdr local))))
  1889.         (make-local-variable (car local))
  1890.         (set (car local) global))
  1891.     ;; Simple nil-valued local variable.
  1892.     (make-local-variable local)
  1893.     (set local nil)))))
  1894.  
  1895. (defun gnus-summary-clear-local-variables ()
  1896.   (let ((locals gnus-summary-local-variables))
  1897.     (while locals
  1898.       (if (consp (car locals))
  1899.       (and (vectorp (caar locals))
  1900.            (set (caar locals) nil))
  1901.     (and (vectorp (car locals))
  1902.          (set (car locals) nil)))
  1903.       (setq locals (cdr locals)))))
  1904.  
  1905. ;; Summary data functions.
  1906.  
  1907. (defmacro gnus-data-number (data)
  1908.   `(car ,data))
  1909.  
  1910. (defmacro gnus-data-set-number (data number)
  1911.   `(setcar ,data ,number))
  1912.  
  1913. (defmacro gnus-data-mark (data)
  1914.   `(nth 1 ,data))
  1915.  
  1916. (defmacro gnus-data-set-mark (data mark)
  1917.   `(setcar (nthcdr 1 ,data) ,mark))
  1918.  
  1919. (defmacro gnus-data-pos (data)
  1920.   `(nth 2 ,data))
  1921.  
  1922. (defmacro gnus-data-set-pos (data pos)
  1923.   `(setcar (nthcdr 2 ,data) ,pos))
  1924.  
  1925. (defmacro gnus-data-header (data)
  1926.   `(nth 3 ,data))
  1927.  
  1928. (defmacro gnus-data-set-header (data header)
  1929.   `(setf (nth 3 ,data) ,header))
  1930.  
  1931. (defmacro gnus-data-level (data)
  1932.   `(nth 4 ,data))
  1933.  
  1934. (defmacro gnus-data-unread-p (data)
  1935.   `(= (nth 1 ,data) gnus-unread-mark))
  1936.  
  1937. (defmacro gnus-data-read-p (data)
  1938.   `(/= (nth 1 ,data) gnus-unread-mark))
  1939.  
  1940. (defmacro gnus-data-pseudo-p (data)
  1941.   `(consp (nth 3 ,data)))
  1942.  
  1943. (defmacro gnus-data-find (number)
  1944.   `(assq ,number gnus-newsgroup-data))
  1945.  
  1946. (defmacro gnus-data-find-list (number &optional data)
  1947.   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
  1948.      (memq (assq ,number bdata)
  1949.        bdata)))
  1950.  
  1951. (defmacro gnus-data-make (number mark pos header level)
  1952.   `(list ,number ,mark ,pos ,header ,level))
  1953.  
  1954. (defun gnus-data-enter (after-article number mark pos header level offset)
  1955.   (let ((data (gnus-data-find-list after-article)))
  1956.     (unless data
  1957.       (error "No such article: %d" after-article))
  1958.     (setcdr data (cons (gnus-data-make number mark pos header level)
  1959.                (cdr data)))
  1960.     (setq gnus-newsgroup-data-reverse nil)
  1961.     (gnus-data-update-list (cddr data) offset)))
  1962.  
  1963. (defun gnus-data-enter-list (after-article list &optional offset)
  1964.   (when list
  1965.     (let ((data (and after-article (gnus-data-find-list after-article)))
  1966.       (ilist list))
  1967.       (or data (not after-article) (error "No such article: %d" after-article))
  1968.       ;; Find the last element in the list to be spliced into the main
  1969.       ;; list.
  1970.       (while (cdr list)
  1971.     (setq list (cdr list)))
  1972.       (if (not data)
  1973.       (progn
  1974.         (setcdr list gnus-newsgroup-data)
  1975.         (setq gnus-newsgroup-data ilist)
  1976.         (when offset
  1977.           (gnus-data-update-list (cdr list) offset)))
  1978.     (setcdr list (cdr data))
  1979.     (setcdr data ilist)
  1980.     (when offset
  1981.       (gnus-data-update-list (cdr list) offset)))
  1982.       (setq gnus-newsgroup-data-reverse nil))))
  1983.  
  1984. (defun gnus-data-remove (article &optional offset)
  1985.   (let ((data gnus-newsgroup-data))
  1986.     (if (= (gnus-data-number (car data)) article)
  1987.     (progn
  1988.       (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
  1989.         gnus-newsgroup-data-reverse nil)
  1990.       (when offset
  1991.         (gnus-data-update-list gnus-newsgroup-data offset)))
  1992.       (while (cdr data)
  1993.     (when (= (gnus-data-number (cadr data)) article)
  1994.       (setcdr data (cddr data))
  1995.       (when offset
  1996.         (gnus-data-update-list (cdr data) offset))
  1997.       (setq data nil
  1998.         gnus-newsgroup-data-reverse nil))
  1999.     (setq data (cdr data))))))
  2000.  
  2001. (defmacro gnus-data-list (backward)
  2002.   `(if ,backward
  2003.        (or gnus-newsgroup-data-reverse
  2004.        (setq gnus-newsgroup-data-reverse
  2005.          (reverse gnus-newsgroup-data)))
  2006.      gnus-newsgroup-data))
  2007.  
  2008. (defun gnus-data-update-list (data offset)
  2009.   "Add OFFSET to the POS of all data entries in DATA."
  2010.   (while data
  2011.     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
  2012.     (setq data (cdr data))))
  2013.  
  2014. (defun gnus-data-compute-positions ()
  2015.   "Compute the positions of all articles."
  2016.   (let ((data gnus-newsgroup-data)
  2017.     pos)
  2018.     (while data
  2019.       (when (setq pos (text-property-any
  2020.                (point-min) (point-max)
  2021.                'gnus-number (gnus-data-number (car data))))
  2022.     (gnus-data-set-pos (car data) (+ pos 3)))
  2023.       (setq data (cdr data)))))
  2024.  
  2025. (defun gnus-summary-article-pseudo-p (article)
  2026.   "Say whether this article is a pseudo article or not."
  2027.   (not (vectorp (gnus-data-header (gnus-data-find article)))))
  2028.  
  2029. (defmacro gnus-summary-article-sparse-p (article)
  2030.   "Say whether this article is a sparse article or not."
  2031.   `(memq ,article gnus-newsgroup-sparse))
  2032.  
  2033. (defmacro gnus-summary-article-ancient-p (article)
  2034.   "Say whether this article is a sparse article or not."
  2035.   `(memq ,article gnus-newsgroup-ancient))
  2036.  
  2037. (defun gnus-article-parent-p (number)
  2038.   "Say whether this article is a parent or not."
  2039.   (let ((data (gnus-data-find-list number)))
  2040.     (and (cdr data)            ; There has to be an article after...
  2041.      (< (gnus-data-level (car data)) ; And it has to have a higher level.
  2042.         (gnus-data-level (nth 1 data))))))
  2043.  
  2044. (defun gnus-article-children (number)
  2045.   "Return a list of all children to NUMBER."
  2046.   (let* ((data (gnus-data-find-list number))
  2047.      (level (gnus-data-level (car data)))
  2048.      children)
  2049.     (setq data (cdr data))
  2050.     (while (and data
  2051.         (= (gnus-data-level (car data)) (1+ level)))
  2052.       (push (gnus-data-number (car data)) children)
  2053.       (setq data (cdr data)))
  2054.     children))
  2055.  
  2056. (defmacro gnus-summary-skip-intangible ()
  2057.   "If the current article is intangible, then jump to a different article."
  2058.   '(let ((to (get-text-property (point) 'gnus-intangible)))
  2059.      (and to (gnus-summary-goto-subject to))))
  2060.  
  2061. (defmacro gnus-summary-article-intangible-p ()
  2062.   "Say whether this article is intangible or not."
  2063.   '(get-text-property (point) 'gnus-intangible))
  2064.  
  2065. (defun gnus-article-read-p (article)
  2066.   "Say whether ARTICLE is read or not."
  2067.   (not (or (memq article gnus-newsgroup-marked)
  2068.        (memq article gnus-newsgroup-unreads)
  2069.        (memq article gnus-newsgroup-unselected)
  2070.        (memq article gnus-newsgroup-dormant))))
  2071.  
  2072. ;; Some summary mode macros.
  2073.  
  2074. (defmacro gnus-summary-article-number ()
  2075.   "The article number of the article on the current line.
  2076. If there isn's an article number here, then we return the current
  2077. article number."
  2078.   '(progn
  2079.      (gnus-summary-skip-intangible)
  2080.      (or (get-text-property (point) 'gnus-number)
  2081.      (gnus-summary-last-subject))))
  2082.  
  2083. (defmacro gnus-summary-article-header (&optional number)
  2084.   `(gnus-data-header (gnus-data-find
  2085.               ,(or number '(gnus-summary-article-number)))))
  2086.  
  2087. (defmacro gnus-summary-thread-level (&optional number)
  2088.   `(if (and (eq gnus-summary-make-false-root 'dummy)
  2089.         (get-text-property (point) 'gnus-intangible))
  2090.        0
  2091.      (gnus-data-level (gnus-data-find
  2092.                ,(or number '(gnus-summary-article-number))))))
  2093.  
  2094. (defmacro gnus-summary-article-mark (&optional number)
  2095.   `(gnus-data-mark (gnus-data-find
  2096.             ,(or number '(gnus-summary-article-number)))))
  2097.  
  2098. (defmacro gnus-summary-article-pos (&optional number)
  2099.   `(gnus-data-pos (gnus-data-find
  2100.            ,(or number '(gnus-summary-article-number)))))
  2101.  
  2102. (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
  2103. (defmacro gnus-summary-article-subject (&optional number)
  2104.   "Return current subject string or nil if nothing."
  2105.   `(let ((headers
  2106.       ,(if number
  2107.            `(gnus-data-header (assq ,number gnus-newsgroup-data))
  2108.          '(gnus-data-header (assq (gnus-summary-article-number)
  2109.                       gnus-newsgroup-data)))))
  2110.      (and headers
  2111.       (vectorp headers)
  2112.       (mail-header-subject headers))))
  2113.  
  2114. (defmacro gnus-summary-article-score (&optional number)
  2115.   "Return current article score."
  2116.   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
  2117.           gnus-newsgroup-scored))
  2118.        gnus-summary-default-score 0))
  2119.  
  2120. (defun gnus-summary-article-children (&optional number)
  2121.   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
  2122.      (level (gnus-data-level (car data)))
  2123.      l children)
  2124.     (while (and (setq data (cdr data))
  2125.         (> (setq l (gnus-data-level (car data))) level))
  2126.       (and (= (1+ level) l)
  2127.        (push (gnus-data-number (car data))
  2128.          children)))
  2129.     (nreverse children)))
  2130.  
  2131. (defun gnus-summary-article-parent (&optional number)
  2132.   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
  2133.                     (gnus-data-list t)))
  2134.      (level (gnus-data-level (car data))))
  2135.     (if (zerop level)
  2136.     ()                ; This is a root.
  2137.       ;; We search until we find an article with a level less than
  2138.       ;; this one.  That function has to be the parent.
  2139.       (while (and (setq data (cdr data))
  2140.           (not (< (gnus-data-level (car data)) level))))
  2141.       (and data (gnus-data-number (car data))))))
  2142.  
  2143. (defun gnus-unread-mark-p (mark)
  2144.   "Say whether MARK is the unread mark."
  2145.   (= mark gnus-unread-mark))
  2146.  
  2147. (defun gnus-read-mark-p (mark)
  2148.   "Say whether MARK is one of the marks that mark as read.
  2149. This is all marks except unread, ticked, dormant, and expirable."
  2150.   (not (or (= mark gnus-unread-mark)
  2151.        (= mark gnus-ticked-mark)
  2152.        (= mark gnus-dormant-mark)
  2153.        (= mark gnus-expirable-mark))))
  2154.  
  2155. (defmacro gnus-article-mark (number)
  2156.   `(cond
  2157.     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
  2158.     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
  2159.     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
  2160.     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
  2161.     (t (or (cdr (assq ,number gnus-newsgroup-reads))
  2162.        gnus-ancient-mark))))
  2163.  
  2164. ;; Saving hidden threads.
  2165.  
  2166. (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
  2167. (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
  2168.  
  2169. (defmacro gnus-save-hidden-threads (&rest forms)
  2170.   "Save hidden threads, eval FORMS, and restore the hidden threads."
  2171.   (let ((config (make-symbol "config")))
  2172.     `(let ((,config (gnus-hidden-threads-configuration)))
  2173.        (unwind-protect
  2174.        (save-excursion
  2175.          ,@forms)
  2176.      (gnus-restore-hidden-threads-configuration ,config)))))
  2177.  
  2178. (defun gnus-hidden-threads-configuration ()
  2179.   "Return the current hidden threads configuration."
  2180.   (save-excursion
  2181.     (let (config)
  2182.       (goto-char (point-min))
  2183.       (while (search-forward "\r" nil t)
  2184.     (push (1- (point)) config))
  2185.       config)))
  2186.  
  2187. (defun gnus-restore-hidden-threads-configuration (config)
  2188.   "Restore hidden threads configuration from CONFIG."
  2189.   (let (point buffer-read-only)
  2190.     (while (setq point (pop config))
  2191.       (when (and (< point (point-max))
  2192.          (goto-char point)
  2193.          (= (following-char) ?\n))
  2194.     (subst-char-in-region point (1+ point) ?\n ?\r)))))
  2195.  
  2196. ;; Various summary mode internalish functions.
  2197.  
  2198. (defun gnus-mouse-pick-article (e)
  2199.   (interactive "e")
  2200.   (mouse-set-point e)
  2201.   (gnus-summary-next-page nil t))
  2202.  
  2203. (defun gnus-summary-set-display-table ()
  2204.   ;; Change the display table.  Odd characters have a tendency to mess
  2205.   ;; up nicely formatted displays - we make all possible glyphs
  2206.   ;; display only a single character.
  2207.  
  2208.   ;; We start from the standard display table, if any.
  2209.   (let ((table (or (copy-sequence standard-display-table)
  2210.            (make-display-table)))
  2211.     (i 32))
  2212.     ;; Nix out all the control chars...
  2213.     (while (>= (setq i (1- i)) 0)
  2214.       (aset table i [??]))
  2215.     ;; ... but not newline and cr, of course.  (cr is necessary for the
  2216.     ;; selective display).
  2217.     (aset table ?\n nil)
  2218.     (aset table ?\r nil)
  2219.     ;; We nix out any glyphs over 126 that are not set already.
  2220.     (let ((i 256))
  2221.       (while (>= (setq i (1- i)) 127)
  2222.     ;; Only modify if the entry is nil.
  2223.     (unless (aref table i)
  2224.       (aset table i [??]))))
  2225.     (setq buffer-display-table table)))
  2226.  
  2227. (defun gnus-summary-setup-buffer (group)
  2228.   "Initialize summary buffer."
  2229.   (let ((buffer (concat "*Summary " group "*")))
  2230.     (if (get-buffer buffer)
  2231.     (progn
  2232.       (set-buffer buffer)
  2233.       (setq gnus-summary-buffer (current-buffer))
  2234.       (not gnus-newsgroup-prepared))
  2235.       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
  2236.       (setq gnus-summary-buffer (set-buffer (get-buffer-create buffer)))
  2237.       (gnus-add-current-to-buffer-list)
  2238.       (gnus-summary-mode group)
  2239.       (when gnus-carpal
  2240.     (gnus-carpal-setup-buffer 'summary))
  2241.       (unless gnus-single-article-buffer
  2242.     (make-local-variable 'gnus-article-buffer)
  2243.     (make-local-variable 'gnus-article-current)
  2244.     (make-local-variable 'gnus-original-article-buffer))
  2245.       (setq gnus-newsgroup-name group)
  2246.       t)))
  2247.  
  2248. (defun gnus-set-global-variables ()
  2249.   ;; Set the global equivalents of the summary buffer-local variables
  2250.   ;; to the latest values they had.  These reflect the summary buffer
  2251.   ;; that was in action when the last article was fetched.
  2252.   (when (eq major-mode 'gnus-summary-mode)
  2253.     (setq gnus-summary-buffer (current-buffer))
  2254.     (let ((name gnus-newsgroup-name)
  2255.       (marked gnus-newsgroup-marked)
  2256.       (unread gnus-newsgroup-unreads)
  2257.       (headers gnus-current-headers)
  2258.       (data gnus-newsgroup-data)
  2259.       (summary gnus-summary-buffer)
  2260.       (article-buffer gnus-article-buffer)
  2261.       (original gnus-original-article-buffer)
  2262.       (gac gnus-article-current)
  2263.       (reffed gnus-reffed-article-number)
  2264.       (score-file gnus-current-score-file))
  2265.       (save-excursion
  2266.     (set-buffer gnus-group-buffer)
  2267.     (setq gnus-newsgroup-name name)
  2268.     (setq gnus-newsgroup-marked marked)
  2269.     (setq gnus-newsgroup-unreads unread)
  2270.     (setq gnus-current-headers headers)
  2271.     (setq gnus-newsgroup-data data)
  2272.     (setq gnus-article-current gac)
  2273.     (setq gnus-summary-buffer summary)
  2274.     (setq gnus-article-buffer article-buffer)
  2275.     (setq gnus-original-article-buffer original)
  2276.     (setq gnus-reffed-article-number reffed)
  2277.     (setq gnus-current-score-file score-file)
  2278.     ;; The article buffer also has local variables.
  2279.     (when (gnus-buffer-live-p gnus-article-buffer)
  2280.       (set-buffer gnus-article-buffer)
  2281.       (setq gnus-summary-buffer summary))))))
  2282.  
  2283. (defun gnus-summary-article-unread-p (article)
  2284.   "Say whether ARTICLE is unread or not."
  2285.   (memq article gnus-newsgroup-unreads))
  2286.  
  2287. (defun gnus-summary-first-article-p (&optional article)
  2288.   "Return whether ARTICLE is the first article in the buffer."
  2289.   (if (not (setq article (or article (gnus-summary-article-number))))
  2290.       nil
  2291.     (eq article (caar gnus-newsgroup-data))))
  2292.  
  2293. (defun gnus-summary-last-article-p (&optional article)
  2294.   "Return whether ARTICLE is the last article in the buffer."
  2295.   (if (not (setq article (or article (gnus-summary-article-number))))
  2296.       t        ; All non-existent numbers are the last article.  :-)
  2297.     (not (cdr (gnus-data-find-list article)))))
  2298.  
  2299. (defun gnus-make-thread-indent-array ()
  2300.   (let ((n 200))
  2301.     (unless (and gnus-thread-indent-array
  2302.          (= gnus-thread-indent-level gnus-thread-indent-array-level))
  2303.       (setq gnus-thread-indent-array (make-vector 201 "")
  2304.         gnus-thread-indent-array-level gnus-thread-indent-level)
  2305.       (while (>= n 0)
  2306.     (aset gnus-thread-indent-array n
  2307.           (make-string (* n gnus-thread-indent-level) ? ))
  2308.     (setq n (1- n))))))
  2309.  
  2310. (defun gnus-update-summary-mark-positions ()
  2311.   "Compute where the summary marks are to go."
  2312.   (save-excursion
  2313.     (when (and gnus-summary-buffer
  2314.            (get-buffer gnus-summary-buffer)
  2315.            (buffer-name (get-buffer gnus-summary-buffer)))
  2316.       (set-buffer gnus-summary-buffer))
  2317.     (let ((gnus-replied-mark 129)
  2318.       (gnus-score-below-mark 130)
  2319.       (gnus-score-over-mark 130)
  2320.       (spec gnus-summary-line-format-spec)
  2321.       thread gnus-visual pos)
  2322.       (save-excursion
  2323.     (gnus-set-work-buffer)
  2324.     (let ((gnus-summary-line-format-spec spec))
  2325.       (gnus-summary-insert-line
  2326.        [0 "" "" "" "" "" 0 0 ""]  0 nil 128 t nil "" nil 1)
  2327.       (goto-char (point-min))
  2328.       (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
  2329.                          (- (point) 2)))))
  2330.       (goto-char (point-min))
  2331.       (push (cons 'replied (and (search-forward "\201" nil t)
  2332.                     (- (point) 2)))
  2333.         pos)
  2334.       (goto-char (point-min))
  2335.       (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
  2336.         pos)))
  2337.       (setq gnus-summary-mark-positions pos))))
  2338.  
  2339. (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
  2340.   "Insert a dummy root in the summary buffer."
  2341.   (beginning-of-line)
  2342.   (gnus-add-text-properties
  2343.    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
  2344.    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
  2345.  
  2346. (defun gnus-summary-insert-line (gnus-tmp-header
  2347.                  gnus-tmp-level gnus-tmp-current
  2348.                  gnus-tmp-unread gnus-tmp-replied
  2349.                  gnus-tmp-expirable gnus-tmp-subject-or-nil
  2350.                  &optional gnus-tmp-dummy gnus-tmp-score
  2351.                  gnus-tmp-process)
  2352.   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
  2353.      (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
  2354.      (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
  2355.      (gnus-tmp-score-char
  2356.       (if (or (null gnus-summary-default-score)
  2357.           (<= (abs (- gnus-tmp-score gnus-summary-default-score))
  2358.               gnus-summary-zcore-fuzz))
  2359.           ? 
  2360.         (if (< gnus-tmp-score gnus-summary-default-score)
  2361.         gnus-score-below-mark gnus-score-over-mark)))
  2362.      (gnus-tmp-replied
  2363.       (cond (gnus-tmp-process gnus-process-mark)
  2364.         ((memq gnus-tmp-current gnus-newsgroup-cached)
  2365.          gnus-cached-mark)
  2366.         (gnus-tmp-replied gnus-replied-mark)
  2367.         ((memq gnus-tmp-current gnus-newsgroup-saved)
  2368.          gnus-saved-mark)
  2369.         (t gnus-unread-mark)))
  2370.      (gnus-tmp-from (mail-header-from gnus-tmp-header))
  2371.      (gnus-tmp-name
  2372.       (cond
  2373.        ((string-match "<[^>]+> *$" gnus-tmp-from)
  2374.         (let ((beg (match-beginning 0)))
  2375.           (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
  2376.                (substring gnus-tmp-from (1+ (match-beginning 0))
  2377.                   (1- (match-end 0))))
  2378.           (substring gnus-tmp-from 0 beg))))
  2379.        ((string-match "(.+)" gnus-tmp-from)
  2380.         (substring gnus-tmp-from
  2381.                (1+ (match-beginning 0)) (1- (match-end 0))))
  2382.        (t gnus-tmp-from)))
  2383.      (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
  2384.      (gnus-tmp-number (mail-header-number gnus-tmp-header))
  2385.      (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
  2386.      (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
  2387.      (buffer-read-only nil))
  2388.     (when (string= gnus-tmp-name "")
  2389.       (setq gnus-tmp-name gnus-tmp-from))
  2390.     (unless (numberp gnus-tmp-lines)
  2391.       (setq gnus-tmp-lines 0))
  2392.     (gnus-put-text-property
  2393.      (point)
  2394.      (progn (eval gnus-summary-line-format-spec) (point))
  2395.      'gnus-number gnus-tmp-number)
  2396.     (when (gnus-visual-p 'summary-highlight 'highlight)
  2397.       (forward-line -1)
  2398.       (run-hooks 'gnus-summary-update-hook)
  2399.       (forward-line 1))))
  2400.  
  2401. (defun gnus-summary-update-line (&optional dont-update)
  2402.   ;; Update summary line after change.
  2403.   (when (and gnus-summary-default-score
  2404.          (not gnus-summary-inhibit-highlight))
  2405.     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
  2406.        (article (gnus-summary-article-number))
  2407.        (score (gnus-summary-article-score article)))
  2408.       (unless dont-update
  2409.     (if (and gnus-summary-mark-below
  2410.          (< (gnus-summary-article-score)
  2411.             gnus-summary-mark-below))
  2412.         ;; This article has a low score, so we mark it as read.
  2413.         (when (memq article gnus-newsgroup-unreads)
  2414.           (gnus-summary-mark-article-as-read gnus-low-score-mark))
  2415.       (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
  2416.         ;; This article was previously marked as read on account
  2417.         ;; of a low score, but now it has risen, so we mark it as
  2418.         ;; unread.
  2419.         (gnus-summary-mark-article-as-unread gnus-unread-mark)))
  2420.     (gnus-summary-update-mark
  2421.      (if (or (null gnus-summary-default-score)
  2422.          (<= (abs (- score gnus-summary-default-score))
  2423.              gnus-summary-zcore-fuzz))
  2424.          ? 
  2425.        (if (< score gnus-summary-default-score)
  2426.            gnus-score-below-mark gnus-score-over-mark))
  2427.      'score))
  2428.       ;; Do visual highlighting.
  2429.       (when (gnus-visual-p 'summary-highlight 'highlight)
  2430.     (run-hooks 'gnus-summary-update-hook)))))
  2431.  
  2432. (defvar gnus-tmp-new-adopts nil)
  2433.  
  2434. (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
  2435.   "Return the number of articles in THREAD.
  2436. This may be 0 in some cases -- if none of the articles in
  2437. the thread are to be displayed."
  2438.   (let* ((number
  2439.       ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
  2440.       (cond
  2441.        ((not (listp thread))
  2442.         1)
  2443.        ((and (consp thread) (cdr thread))
  2444.         (apply
  2445.          '+ 1 (mapcar
  2446.            'gnus-summary-number-of-articles-in-thread (cdr thread))))
  2447.        ((null thread)
  2448.         1)
  2449.        ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
  2450.         1)
  2451.        (t 0))))
  2452.     (when (and level (zerop level) gnus-tmp-new-adopts)
  2453.       (incf number
  2454.         (apply '+ (mapcar
  2455.                'gnus-summary-number-of-articles-in-thread
  2456.                gnus-tmp-new-adopts))))
  2457.     (if char
  2458.     (if (> number 1) gnus-not-empty-thread-mark
  2459.       gnus-empty-thread-mark)
  2460.       number)))
  2461.  
  2462. (defun gnus-summary-set-local-parameters (group)
  2463.   "Go through the local params of GROUP and set all variable specs in that list."
  2464.   (let ((params (gnus-group-find-parameter group))
  2465.     elem)
  2466.     (while params
  2467.       (setq elem (car params)
  2468.         params (cdr params))
  2469.       (and (consp elem)            ; Has to be a cons.
  2470.        (consp (cdr elem))        ; The cdr has to be a list.
  2471.        (symbolp (car elem))        ; Has to be a symbol in there.
  2472.        (not (memq (car elem)
  2473.               '(quit-config to-address to-list to-group)))
  2474.        (ignore-errors        ; So we set it.
  2475.          (make-local-variable (car elem))
  2476.          (set (car elem) (eval (nth 1 elem))))))))
  2477.  
  2478. (defun gnus-summary-read-group (group &optional show-all no-article
  2479.                       kill-buffer no-display)
  2480.   "Start reading news in newsgroup GROUP.
  2481. If SHOW-ALL is non-nil, already read articles are also listed.
  2482. If NO-ARTICLE is non-nil, no article is selected initially.
  2483. If NO-DISPLAY, don't generate a summary buffer."
  2484.   (let (result)
  2485.     (while (and group
  2486.         (null (setq result
  2487.                 (let ((gnus-auto-select-next nil))
  2488.                   (gnus-summary-read-group-1
  2489.                    group show-all no-article
  2490.                    kill-buffer no-display))))
  2491.         (eq gnus-auto-select-next 'quietly))
  2492.       (set-buffer gnus-group-buffer)
  2493.       (if (not (equal group (gnus-group-group-name)))
  2494.       (setq group (gnus-group-group-name))
  2495.     (setq group nil)))
  2496.     result))
  2497.  
  2498. (defun gnus-summary-read-group-1 (group show-all no-article
  2499.                     kill-buffer no-display)
  2500.   ;; Killed foreign groups can't be entered.
  2501.   (when (and (not (gnus-group-native-p group))
  2502.          (not (gnus-gethash group gnus-newsrc-hashtb)))
  2503.     (error "Dead non-native groups can't be entered"))
  2504.   (gnus-message 5 "Retrieving newsgroup: %s..." group)
  2505.   (let* ((new-group (gnus-summary-setup-buffer group))
  2506.      (quit-config (gnus-group-quit-config group))
  2507.      (did-select (and new-group (gnus-select-newsgroup group show-all))))
  2508.     (cond
  2509.      ;; This summary buffer exists already, so we just select it.
  2510.      ((not new-group)
  2511.       (gnus-set-global-variables)
  2512.       (when kill-buffer
  2513.     (gnus-kill-or-deaden-summary kill-buffer))
  2514.       (gnus-configure-windows 'summary 'force)
  2515.       (gnus-set-mode-line 'summary)
  2516.       (gnus-summary-position-point)
  2517.       (message "")
  2518.       t)
  2519.      ;; We couldn't select this group.
  2520.      ((null did-select)
  2521.       (when (and (eq major-mode 'gnus-summary-mode)
  2522.          (not (equal (current-buffer) kill-buffer)))
  2523.     (kill-buffer (current-buffer))
  2524.     (if (not quit-config)
  2525.         (progn
  2526.           (set-buffer gnus-group-buffer)
  2527.           (gnus-group-jump-to-group group)
  2528.           (gnus-group-next-unread-group 1))
  2529.       (gnus-handle-ephemeral-exit quit-config)))
  2530.       (gnus-message 3 "Can't select group")
  2531.       nil)
  2532.      ;; The user did a `C-g' while prompting for number of articles,
  2533.      ;; so we exit this group.
  2534.      ((eq did-select 'quit)
  2535.       (and (eq major-mode 'gnus-summary-mode)
  2536.        (not (equal (current-buffer) kill-buffer))
  2537.        (kill-buffer (current-buffer)))
  2538.       (when kill-buffer
  2539.     (gnus-kill-or-deaden-summary kill-buffer))
  2540.       (if (not quit-config)
  2541.       (progn
  2542.         (set-buffer gnus-group-buffer)
  2543.         (gnus-group-jump-to-group group)
  2544.         (gnus-group-next-unread-group 1)
  2545.         (gnus-configure-windows 'group 'force))
  2546.     (gnus-handle-ephemeral-exit quit-config))
  2547.       ;; Finally signal the quit.
  2548.       (signal 'quit nil))
  2549.      ;; The group was successfully selected.
  2550.      (t
  2551.       (gnus-set-global-variables)
  2552.       ;; Save the active value in effect when the group was entered.
  2553.       (setq gnus-newsgroup-active
  2554.         (gnus-copy-sequence
  2555.          (gnus-active gnus-newsgroup-name)))
  2556.       ;; You can change the summary buffer in some way with this hook.
  2557.       (run-hooks 'gnus-select-group-hook)
  2558.       ;; Set any local variables in the group parameters.
  2559.       (gnus-summary-set-local-parameters gnus-newsgroup-name)
  2560.       (gnus-update-format-specifications
  2561.        nil 'summary 'summary-mode 'summary-dummy)
  2562.       ;; Do score processing.
  2563.       (when gnus-use-scoring
  2564.     (gnus-possibly-score-headers))
  2565.       ;; Check whether to fill in the gaps in the threads.
  2566.       (when gnus-build-sparse-threads
  2567.     (gnus-build-sparse-threads))
  2568.       ;; Find the initial limit.
  2569.       (if gnus-show-threads
  2570.       (if show-all
  2571.           (let ((gnus-newsgroup-dormant nil))
  2572.         (gnus-summary-initial-limit show-all))
  2573.         (gnus-summary-initial-limit show-all))
  2574.     (setq gnus-newsgroup-limit
  2575.           (mapcar
  2576.            (lambda (header) (mail-header-number header))
  2577.            gnus-newsgroup-headers)))
  2578.       ;; Generate the summary buffer.
  2579.       (unless no-display
  2580.     (gnus-summary-prepare))
  2581.       (when gnus-use-trees
  2582.     (gnus-tree-open group)
  2583.     (setq gnus-summary-highlight-line-function
  2584.           'gnus-tree-highlight-article))
  2585.       ;; If the summary buffer is empty, but there are some low-scored
  2586.       ;; articles or some excluded dormants, we include these in the
  2587.       ;; buffer.
  2588.       (when (and (zerop (buffer-size))
  2589.          (not no-display))
  2590.     (cond (gnus-newsgroup-dormant
  2591.            (gnus-summary-limit-include-dormant))
  2592.           ((and gnus-newsgroup-scored show-all)
  2593.            (gnus-summary-limit-include-expunged t))))
  2594.       ;; Function `gnus-apply-kill-file' must be called in this hook.
  2595.       (run-hooks 'gnus-apply-kill-hook)
  2596.       (if (and (zerop (buffer-size))
  2597.            (not no-display))
  2598.       (progn
  2599.         ;; This newsgroup is empty.
  2600.         (gnus-summary-catchup-and-exit nil t)
  2601.         (gnus-message 6 "No unread news")
  2602.         (when kill-buffer
  2603.           (gnus-kill-or-deaden-summary kill-buffer))
  2604.         ;; Return nil from this function.
  2605.         nil)
  2606.     ;; Hide conversation thread subtrees.  We cannot do this in
  2607.     ;; gnus-summary-prepare-hook since kill processing may not
  2608.     ;; work with hidden articles.
  2609.     (and gnus-show-threads
  2610.          gnus-thread-hide-subtree
  2611.          (gnus-summary-hide-all-threads))
  2612.     ;; Show first unread article if requested.
  2613.     (if (and (not no-article)
  2614.          (not no-display)
  2615.          gnus-newsgroup-unreads
  2616.          gnus-auto-select-first)
  2617.         (unless (if (eq gnus-auto-select-first 'best)
  2618.             (gnus-summary-best-unread-article)
  2619.               (gnus-summary-first-unread-article))
  2620.           (gnus-configure-windows 'summary))
  2621.       ;; Don't select any articles, just move point to the first
  2622.       ;; article in the group.
  2623.       (goto-char (point-min))
  2624.       (gnus-summary-position-point)
  2625.       (gnus-set-mode-line 'summary)
  2626.       (gnus-configure-windows 'summary 'force))
  2627.     (when kill-buffer
  2628.       (gnus-kill-or-deaden-summary kill-buffer))
  2629.     (when (get-buffer-window gnus-group-buffer t)
  2630.       ;; Gotta use windows, because recenter does weird stuff if
  2631.       ;; the current buffer ain't the displayed window.
  2632.       (let ((owin (selected-window)))
  2633.         (select-window (get-buffer-window gnus-group-buffer t))
  2634.         (when (gnus-group-goto-group group)
  2635.           (recenter))
  2636.         (select-window owin)))
  2637.     ;; Mark this buffer as "prepared".
  2638.     (setq gnus-newsgroup-prepared t)
  2639.     t)))))
  2640.  
  2641. (defun gnus-summary-prepare ()
  2642.   "Generate the summary buffer."
  2643.   (interactive)
  2644.   (let ((buffer-read-only nil))
  2645.     (erase-buffer)
  2646.     (setq gnus-newsgroup-data nil
  2647.       gnus-newsgroup-data-reverse nil)
  2648.     (run-hooks 'gnus-summary-generate-hook)
  2649.     ;; Generate the buffer, either with threads or without.
  2650.     (when gnus-newsgroup-headers
  2651.       (gnus-summary-prepare-threads
  2652.        (if gnus-show-threads
  2653.        (gnus-sort-gathered-threads
  2654.         (funcall gnus-summary-thread-gathering-function
  2655.              (gnus-sort-threads
  2656.               (gnus-cut-threads (gnus-make-threads)))))
  2657.      ;; Unthreaded display.
  2658.      (gnus-sort-articles gnus-newsgroup-headers))))
  2659.     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
  2660.     ;; Call hooks for modifying summary buffer.
  2661.     (goto-char (point-min))
  2662.     (run-hooks 'gnus-summary-prepare-hook)))
  2663.  
  2664. (defsubst gnus-general-simplify-subject (subject)
  2665.   "Simply subject by the same rules as gnus-gather-threads-by-subject."
  2666.   (setq subject
  2667.     (cond
  2668.      ;; Truncate the subject.
  2669.      ((numberp gnus-summary-gather-subject-limit)
  2670.       (setq subject (gnus-simplify-subject-re subject))
  2671.       (if (> (length subject) gnus-summary-gather-subject-limit)
  2672.           (substring subject 0 gnus-summary-gather-subject-limit)
  2673.         subject))
  2674.      ;; Fuzzily simplify it.
  2675.      ((eq 'fuzzy gnus-summary-gather-subject-limit)
  2676.       (gnus-simplify-subject-fuzzy subject))
  2677.      ;; Just remove the leading "Re:".
  2678.      (t
  2679.       (gnus-simplify-subject-re subject))))
  2680.  
  2681.   (if (and gnus-summary-gather-exclude-subject
  2682.        (string-match gnus-summary-gather-exclude-subject subject))
  2683.       nil                ; This article shouldn't be gathered
  2684.     subject))
  2685.  
  2686. (defun gnus-summary-simplify-subject-query ()
  2687.   "Query where the respool algorithm would put this article."
  2688.   (interactive)
  2689.   (gnus-set-global-variables)
  2690.   (gnus-summary-select-article)
  2691.   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
  2692.  
  2693. (defun gnus-gather-threads-by-subject (threads)
  2694.   "Gather threads by looking at Subject headers."
  2695.   (if (not gnus-summary-make-false-root)
  2696.       threads
  2697.     (let ((hashtb (gnus-make-hashtable 1024))
  2698.       (prev threads)
  2699.       (result threads)
  2700.       subject hthread whole-subject)
  2701.       (while threads
  2702.     (setq subject (gnus-general-simplify-subject
  2703.                (setq whole-subject (mail-header-subject
  2704.                         (caar threads)))))
  2705.     (when subject
  2706.       (if (setq hthread (gnus-gethash subject hashtb))
  2707.           (progn
  2708.         ;; We enter a dummy root into the thread, if we
  2709.         ;; haven't done that already.
  2710.         (unless (stringp (caar hthread))
  2711.           (setcar hthread (list whole-subject (car hthread))))
  2712.         ;; We add this new gathered thread to this gathered
  2713.         ;; thread.
  2714.         (setcdr (car hthread)
  2715.             (nconc (cdar hthread) (list (car threads))))
  2716.         ;; Remove it from the list of threads.
  2717.         (setcdr prev (cdr threads))
  2718.         (setq threads prev))
  2719.         ;; Enter this thread into the hash table.
  2720.         (gnus-sethash subject threads hashtb)))
  2721.     (setq prev threads)
  2722.     (setq threads (cdr threads)))
  2723.       result)))
  2724.  
  2725. (defun gnus-gather-threads-by-references (threads)
  2726.   "Gather threads by looking at References headers."
  2727.   (let ((idhashtb (gnus-make-hashtable 1024))
  2728.     (thhashtb (gnus-make-hashtable 1024))
  2729.     (prev threads)
  2730.     (result threads)
  2731.     ids references id gthread gid entered ref)
  2732.     (while threads
  2733.       (when (setq references (mail-header-references (caar threads)))
  2734.     (setq id (mail-header-id (caar threads))
  2735.           ids (gnus-split-references references)
  2736.           entered nil)
  2737.     (while (setq ref (pop ids))
  2738.       (setq ids (delete ref ids))
  2739.       (if (not (setq gid (gnus-gethash ref idhashtb)))
  2740.           (progn
  2741.         (gnus-sethash ref id idhashtb)
  2742.         (gnus-sethash id threads thhashtb))
  2743.         (setq gthread (gnus-gethash gid thhashtb))
  2744.         (unless entered
  2745.           ;; We enter a dummy root into the thread, if we
  2746.           ;; haven't done that already.
  2747.           (unless (stringp (caar gthread))
  2748.         (setcar gthread (list (mail-header-subject (caar gthread))
  2749.                       (car gthread))))
  2750.           ;; We add this new gathered thread to this gathered
  2751.           ;; thread.
  2752.           (setcdr (car gthread)
  2753.               (nconc (cdar gthread) (list (car threads)))))
  2754.         ;; Add it into the thread hash table.
  2755.         (gnus-sethash id gthread thhashtb)
  2756.         (setq entered t)
  2757.         ;; Remove it from the list of threads.
  2758.         (setcdr prev (cdr threads))
  2759.         (setq threads prev))))
  2760.       (setq prev threads)
  2761.       (setq threads (cdr threads)))
  2762.     result))
  2763.  
  2764. (defun gnus-sort-gathered-threads (threads)
  2765.   "Sort subtreads inside each gathered thread by article number."
  2766.   (let ((result threads))
  2767.     (while threads
  2768.       (when (stringp (caar threads))
  2769.     (setcdr (car threads)
  2770.         (sort (cdar threads) 'gnus-thread-sort-by-number)))
  2771.       (setq threads (cdr threads)))
  2772.     result))
  2773.  
  2774. (defun gnus-thread-loop-p (root thread)
  2775.   "Say whether ROOT is in THREAD."
  2776.   (let ((stack (list thread))
  2777.     (infloop 0)
  2778.     th)
  2779.     (while (setq thread (pop stack))
  2780.       (setq th (cdr thread))
  2781.       (while (and th
  2782.           (not (eq (caar th) root)))
  2783.     (pop th))
  2784.       (if th
  2785.       ;; We have found a loop.
  2786.       (let (ref-dep)
  2787.         (setcdr thread (delq (car th) (cdr thread)))
  2788.         (if (boundp (setq ref-dep (intern "none"
  2789.                           gnus-newsgroup-dependencies)))
  2790.         (setcdr (symbol-value ref-dep)
  2791.             (nconc (cdr (symbol-value ref-dep))
  2792.                    (list (car th))))
  2793.           (set ref-dep (list nil (car th))))
  2794.         (setq infloop 1
  2795.           stack nil))
  2796.     ;; Push all the subthreads onto the stack.
  2797.     (push (cdr thread) stack)))
  2798.     infloop))
  2799.  
  2800. (defun gnus-make-threads ()
  2801.   "Go through the dependency hashtb and find the roots.     Return all threads."
  2802.   (let (threads)
  2803.     (while (catch 'infloop
  2804.          (mapatoms
  2805.           (lambda (refs)
  2806.         ;; Deal with self-referencing References loops.
  2807.         (when (and (car (symbol-value refs))
  2808.                (not (zerop
  2809.                  (apply
  2810.                   '+
  2811.                   (mapcar
  2812.                    (lambda (thread)
  2813.                      (gnus-thread-loop-p
  2814.                       (car (symbol-value refs)) thread))
  2815.                    (cdr (symbol-value refs)))))))
  2816.           (setq threads nil)
  2817.           (throw 'infloop t))
  2818.         (unless (car (symbol-value refs))
  2819.           ;; These threads do not refer back to any other articles,
  2820.           ;; so they're roots.
  2821.           (setq threads (append (cdr (symbol-value refs)) threads))))
  2822.           gnus-newsgroup-dependencies)))
  2823.     threads))
  2824.  
  2825. (defun gnus-build-sparse-threads ()
  2826.   (let ((headers gnus-newsgroup-headers)
  2827.     (deps gnus-newsgroup-dependencies)
  2828.     header references generation relations
  2829.     cthread subject child end pthread relation)
  2830.     ;; First we create an alist of generations/relations, where
  2831.     ;; generations is how much we trust the relation, and the relation
  2832.     ;; is parent/child.
  2833.     (gnus-message 7 "Making sparse threads...")
  2834.     (save-excursion
  2835.       (nnheader-set-temp-buffer " *gnus sparse threads*")
  2836.       (while (setq header (pop headers))
  2837.     (when (and (setq references (mail-header-references header))
  2838.            (not (string= references "")))
  2839.       (insert references)
  2840.       (setq child (mail-header-id header)
  2841.         subject (mail-header-subject header))
  2842.       (setq generation 0)
  2843.       (while (search-backward ">" nil t)
  2844.         (setq end (1+ (point)))
  2845.         (when (search-backward "<" nil t)
  2846.           (push (list (incf generation)
  2847.               child (setq child (buffer-substring (point) end))
  2848.               subject)
  2849.             relations)))
  2850.       (push (list (1+ generation) child nil subject) relations)
  2851.       (erase-buffer)))
  2852.       (kill-buffer (current-buffer)))
  2853.     ;; Sort over trustworthiness.
  2854.     (setq relations (sort relations (lambda (r1 r2) (< (car r1) (car r2)))))
  2855.     (while (setq relation (pop relations))
  2856.       (when (if (boundp (setq cthread (intern (cadr relation) deps)))
  2857.         (unless (car (symbol-value cthread))
  2858.           ;; Make this article the parent of these threads.
  2859.           (setcar (symbol-value cthread)
  2860.               (vector gnus-reffed-article-number
  2861.                   (cadddr relation)
  2862.                   "" ""
  2863.                   (cadr relation)
  2864.                   (or (caddr relation) "") 0 0 "")))
  2865.           (set cthread (list (vector gnus-reffed-article-number
  2866.                      (cadddr relation)
  2867.                      "" "" (cadr relation)
  2868.                      (or (caddr relation) "") 0 0 ""))))
  2869.     (push gnus-reffed-article-number gnus-newsgroup-limit)
  2870.     (push gnus-reffed-article-number gnus-newsgroup-sparse)
  2871.     (push (cons gnus-reffed-article-number gnus-sparse-mark)
  2872.           gnus-newsgroup-reads)
  2873.     (decf gnus-reffed-article-number)
  2874.     ;; Make this new thread the child of its parent.
  2875.     (if (boundp (setq pthread (intern (or (caddr relation) "none") deps)))
  2876.         (setcdr (symbol-value pthread)
  2877.             (nconc (cdr (symbol-value pthread))
  2878.                (list (symbol-value cthread))))
  2879.       (set pthread (list nil (symbol-value cthread))))))
  2880.     (gnus-message 7 "Making sparse threads...done")))
  2881.  
  2882. (defun gnus-build-old-threads ()
  2883.   ;; Look at all the articles that refer back to old articles, and
  2884.   ;; fetch the headers for the articles that aren't there.  This will
  2885.   ;; build complete threads - if the roots haven't been expired by the
  2886.   ;; server, that is.
  2887.   (let (id heads)
  2888.     (mapatoms
  2889.      (lambda (refs)
  2890.        (when (not (car (symbol-value refs)))
  2891.      (setq heads (cdr (symbol-value refs)))
  2892.      (while heads
  2893.        (if (memq (mail-header-number (caar heads))
  2894.              gnus-newsgroup-dormant)
  2895.            (setq heads (cdr heads))
  2896.          (setq id (symbol-name refs))
  2897.          (while (and (setq id (gnus-build-get-header id))
  2898.              (not (car (gnus-gethash
  2899.                     id gnus-newsgroup-dependencies)))))
  2900.          (setq heads nil)))))
  2901.      gnus-newsgroup-dependencies)))
  2902.  
  2903. (defun gnus-build-get-header (id)
  2904.   ;; Look through the buffer of NOV lines and find the header to
  2905.   ;; ID.  Enter this line into the dependencies hash table, and return
  2906.   ;; the id of the parent article (if any).
  2907.   (let ((deps gnus-newsgroup-dependencies)
  2908.     found header)
  2909.     (prog1
  2910.     (save-excursion
  2911.       (set-buffer nntp-server-buffer)
  2912.       (let ((case-fold-search nil))
  2913.         (goto-char (point-min))
  2914.         (while (and (not found)
  2915.             (search-forward id nil t))
  2916.           (beginning-of-line)
  2917.           (setq found (looking-at
  2918.                (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
  2919.                    (regexp-quote id))))
  2920.           (or found (beginning-of-line 2)))
  2921.         (when found
  2922.           (beginning-of-line)
  2923.           (and
  2924.            (setq header (gnus-nov-parse-line
  2925.                  (read (current-buffer)) deps))
  2926.            (gnus-parent-id (mail-header-references header))))))
  2927.       (when header
  2928.     (let ((number (mail-header-number header)))
  2929.       (push number gnus-newsgroup-limit)
  2930.       (push header gnus-newsgroup-headers)
  2931.       (if (memq number gnus-newsgroup-unselected)
  2932.           (progn
  2933.         (push number gnus-newsgroup-unreads)
  2934.         (setq gnus-newsgroup-unselected
  2935.               (delq number gnus-newsgroup-unselected)))
  2936.         (push number gnus-newsgroup-ancient)))))))
  2937.  
  2938. (defun gnus-summary-update-article-line (article header)
  2939.   "Update the line for ARTICLE using HEADERS."
  2940.   (let* ((id (mail-header-id header))
  2941.      (thread (gnus-id-to-thread id)))
  2942.     (unless thread
  2943.       (error "Article in no thread"))
  2944.     ;; Update the thread.
  2945.     (setcar thread header)
  2946.     (gnus-summary-goto-subject article)
  2947.     (let* ((datal (gnus-data-find-list article))
  2948.        (data (car datal))
  2949.        (length (when (cdr datal)
  2950.              (- (gnus-data-pos data)
  2951.             (gnus-data-pos (cadr datal)))))
  2952.        (buffer-read-only nil)
  2953.        (level (gnus-summary-thread-level)))
  2954.       (gnus-delete-line)
  2955.       (gnus-summary-insert-line
  2956.        header level nil (gnus-article-mark article)
  2957.        (memq article gnus-newsgroup-replied)
  2958.        (memq article gnus-newsgroup-expirable)
  2959.        ;; Only insert the Subject string when it's different
  2960.        ;; from the previous Subject string.
  2961.        (if (gnus-subject-equal
  2962.         (condition-case ()
  2963.         (mail-header-subject
  2964.          (gnus-data-header
  2965.           (cadr
  2966.            (gnus-data-find-list
  2967.             article
  2968.             (gnus-data-list t)))))
  2969.           ;; Error on the side of excessive subjects.
  2970.           (error ""))
  2971.         (mail-header-subject header))
  2972.        ""
  2973.      (mail-header-subject header))
  2974.        nil (cdr (assq article gnus-newsgroup-scored))
  2975.        (memq article gnus-newsgroup-processable))
  2976.       (when length
  2977.     (gnus-data-update-list
  2978.      (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
  2979.  
  2980. (defun gnus-summary-update-article (article &optional iheader)
  2981.   "Update ARTICLE in the summary buffer."
  2982.   (set-buffer gnus-summary-buffer)
  2983.   (let* ((header (or iheader (gnus-summary-article-header article)))
  2984.      (id (mail-header-id header))
  2985.      (data (gnus-data-find article))
  2986.      (thread (gnus-id-to-thread id))
  2987.      (references (mail-header-references header))
  2988.      (parent
  2989.       (gnus-id-to-thread
  2990.        (or (gnus-parent-id
  2991.         (when (and references
  2992.                (not (equal "" references)))
  2993.           references))
  2994.            "none")))
  2995.      (buffer-read-only nil)
  2996.      (old (car thread))
  2997.      (number (mail-header-number header))
  2998.      pos)
  2999.     (when thread
  3000.       ;; !!! Should this be in or not?
  3001.       (unless iheader
  3002.     (setcar thread nil))
  3003.       (when parent
  3004.     (delq thread parent))
  3005.       (if (gnus-summary-insert-subject id header iheader)
  3006.       ;; Set the (possibly) new article number in the data structure.
  3007.       (gnus-data-set-number data (gnus-id-to-article id))
  3008.     (setcar thread old)
  3009.     nil))))
  3010.  
  3011. (defun gnus-rebuild-thread (id)
  3012.   "Rebuild the thread containing ID."
  3013.   (let ((buffer-read-only nil)
  3014.     old-pos current thread data)
  3015.     (if (not gnus-show-threads)
  3016.     (setq thread (list (car (gnus-id-to-thread id))))
  3017.       ;; Get the thread this article is part of.
  3018.       (setq thread (gnus-remove-thread id)))
  3019.     (setq old-pos (gnus-point-at-bol))
  3020.     (setq current (save-excursion
  3021.             (and (zerop (forward-line -1))
  3022.              (gnus-summary-article-number))))
  3023.     ;; If this is a gathered thread, we have to go some re-gathering.
  3024.     (when (stringp (car thread))
  3025.       (let ((subject (car thread))
  3026.         roots thr)
  3027.     (setq thread (cdr thread))
  3028.     (while thread
  3029.       (unless (memq (setq thr (gnus-id-to-thread
  3030.                    (gnus-root-id
  3031.                     (mail-header-id (caar thread)))))
  3032.             roots)
  3033.         (push thr roots))
  3034.       (setq thread (cdr thread)))
  3035.     ;; We now have all (unique) roots.
  3036.     (if (= (length roots) 1)
  3037.         ;; All the loose roots are now one solid root.
  3038.         (setq thread (car roots))
  3039.       (setq thread (cons subject (gnus-sort-threads roots))))))
  3040.     (let (threads)
  3041.       ;; We then insert this thread into the summary buffer.
  3042.       (let (gnus-newsgroup-data gnus-newsgroup-threads)
  3043.     (if gnus-show-threads
  3044.         (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
  3045.       (gnus-summary-prepare-unthreaded thread))
  3046.     (setq data (nreverse gnus-newsgroup-data))
  3047.     (setq threads gnus-newsgroup-threads))
  3048.       ;; We splice the new data into the data structure.
  3049.       (gnus-data-enter-list current data (- (point) old-pos))
  3050.       (setq gnus-newsgroup-threads (nconc threads gnus-newsgroup-threads)))))
  3051.  
  3052. (defun gnus-number-to-header (number)
  3053.   "Return the header for article NUMBER."
  3054.   (let ((headers gnus-newsgroup-headers))
  3055.     (while (and headers
  3056.         (not (= number (mail-header-number (car headers)))))
  3057.       (pop headers))
  3058.     (when headers
  3059.       (car headers))))
  3060.  
  3061. (defun gnus-parent-headers (headers &optional generation)
  3062.   "Return the headers of the GENERATIONeth parent of HEADERS."
  3063.   (unless generation
  3064.     (setq generation 1))
  3065.   (let ((parent t)
  3066.     references)
  3067.     (while (and parent headers (not (zerop generation)))
  3068.       (setq references (mail-header-references headers))
  3069.       (when (and references
  3070.          (setq parent (gnus-parent-id references))
  3071.          (setq headers (car (gnus-id-to-thread parent))))
  3072.     (decf generation)))
  3073.     headers))
  3074.  
  3075. (defun gnus-id-to-thread (id)
  3076.   "Return the (sub-)thread where ID appears."
  3077.   (gnus-gethash id gnus-newsgroup-dependencies))
  3078.  
  3079. (defun gnus-id-to-article (id)
  3080.   "Return the article number of ID."
  3081.   (let ((thread (gnus-id-to-thread id)))
  3082.     (when (and thread
  3083.            (car thread))
  3084.       (mail-header-number (car thread)))))
  3085.  
  3086. (defun gnus-id-to-header (id)
  3087.   "Return the article headers of ID."
  3088.   (car (gnus-id-to-thread id)))
  3089.  
  3090. (defun gnus-article-displayed-root-p (article)
  3091.   "Say whether ARTICLE is a root(ish) article."
  3092.   (let ((level (gnus-summary-thread-level article))
  3093.     (refs (mail-header-references  (gnus-summary-article-header article)))
  3094.     particle)
  3095.     (cond
  3096.      ((null level) nil)
  3097.      ((zerop level) t)
  3098.      ((null refs) t)
  3099.      ((null (gnus-parent-id refs)) t)
  3100.      ((and (= 1 level)
  3101.        (null (setq particle (gnus-id-to-article
  3102.                  (gnus-parent-id refs))))
  3103.        (null (gnus-summary-thread-level particle)))))))
  3104.  
  3105. (defun gnus-root-id (id)
  3106.   "Return the id of the root of the thread where ID appears."
  3107.   (let (last-id prev)
  3108.     (while (and id (setq prev (car (gnus-gethash
  3109.                     id gnus-newsgroup-dependencies))))
  3110.       (setq last-id id
  3111.         id (gnus-parent-id (mail-header-references prev))))
  3112.     last-id))
  3113.  
  3114. (defun gnus-remove-thread (id &optional dont-remove)
  3115.   "Remove the thread that has ID in it."
  3116.   (let ((dep gnus-newsgroup-dependencies)
  3117.     headers thread last-id)
  3118.     ;; First go up in this thread until we find the root.
  3119.     (setq last-id (gnus-root-id id))
  3120.     (setq headers (list (car (gnus-id-to-thread last-id))
  3121.             (caadr (gnus-id-to-thread last-id))))
  3122.     ;; We have now found the real root of this thread.    It might have
  3123.     ;; been gathered into some loose thread, so we have to search
  3124.     ;; through the threads to find the thread we wanted.
  3125.     (let ((threads gnus-newsgroup-threads)
  3126.       sub)
  3127.       (while threads
  3128.     (setq sub (car threads))
  3129.     (if (stringp (car sub))
  3130.         ;; This is a gathered thread, so we look at the roots
  3131.         ;; below it to find whether this article is in this
  3132.         ;; gathered root.
  3133.         (progn
  3134.           (setq sub (cdr sub))
  3135.           (while sub
  3136.         (when (member (caar sub) headers)
  3137.           (setq thread (car threads)
  3138.             threads nil
  3139.             sub nil))
  3140.         (setq sub (cdr sub))))
  3141.       ;; It's an ordinary thread, so we check it.
  3142.       (when (eq (car sub) (car headers))
  3143.         (setq thread sub
  3144.           threads nil)))
  3145.     (setq threads (cdr threads)))
  3146.       ;; If this article is in no thread, then it's a root.
  3147.       (if thread
  3148.       (unless dont-remove
  3149.         (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
  3150.     (setq thread (gnus-gethash last-id dep)))
  3151.       (when thread
  3152.     (prog1
  3153.         thread            ; We return this thread.
  3154.       (unless dont-remove
  3155.         (if (stringp (car thread))
  3156.         (progn
  3157.           ;; If we use dummy roots, then we have to remove the
  3158.           ;; dummy root as well.
  3159.           (when (eq gnus-summary-make-false-root 'dummy)
  3160.             (gnus-delete-line)
  3161.             (gnus-data-compute-positions))
  3162.           (setq thread (cdr thread))
  3163.           (while thread
  3164.             (gnus-remove-thread-1 (car thread))
  3165.             (setq thread (cdr thread))))
  3166.           (gnus-remove-thread-1 thread))))))))
  3167.  
  3168. (defun gnus-remove-thread-1 (thread)
  3169.   "Remove the thread THREAD recursively."
  3170.   (let ((number (mail-header-number (pop thread)))
  3171.     d)
  3172.     (setq thread (reverse thread))
  3173.     (while thread
  3174.       (gnus-remove-thread-1 (pop thread)))
  3175.     (when (setq d (gnus-data-find number))
  3176.       (goto-char (gnus-data-pos d))
  3177.       (gnus-data-remove
  3178.        number
  3179.        (- (gnus-point-at-bol)
  3180.       (prog1
  3181.           (1+ (gnus-point-at-eol))
  3182.         (gnus-delete-line)))))))
  3183.  
  3184. (defun gnus-sort-threads (threads)
  3185.   "Sort THREADS."
  3186.   (if (not gnus-thread-sort-functions)
  3187.       threads
  3188.     (gnus-message 7 "Sorting threads...")
  3189.     (prog1
  3190.     (sort threads (gnus-make-sort-function gnus-thread-sort-functions))
  3191.       (gnus-message 7 "Sorting threads...done"))))
  3192.  
  3193. (defun gnus-sort-articles (articles)
  3194.   "Sort ARTICLES."
  3195.   (when gnus-article-sort-functions
  3196.     (gnus-message 7 "Sorting articles...")
  3197.     (prog1
  3198.     (setq gnus-newsgroup-headers
  3199.           (sort articles (gnus-make-sort-function
  3200.                   gnus-article-sort-functions)))
  3201.       (gnus-message 7 "Sorting articles...done"))))
  3202.  
  3203. ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
  3204. (defmacro gnus-thread-header (thread)
  3205.   ;; Return header of first article in THREAD.
  3206.   ;; Note that THREAD must never, ever be anything else than a variable -
  3207.   ;; using some other form will lead to serious barfage.
  3208.   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
  3209.   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
  3210.   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ;
  3211.     (vector thread) 2))
  3212.  
  3213. (defsubst gnus-article-sort-by-number (h1 h2)
  3214.   "Sort articles by article number."
  3215.   (< (mail-header-number h1)
  3216.      (mail-header-number h2)))
  3217.  
  3218. (defun gnus-thread-sort-by-number (h1 h2)
  3219.   "Sort threads by root article number."
  3220.   (gnus-article-sort-by-number
  3221.    (gnus-thread-header h1) (gnus-thread-header h2)))
  3222.  
  3223. (defsubst gnus-article-sort-by-lines (h1 h2)
  3224.   "Sort articles by article Lines header."
  3225.   (< (mail-header-lines h1)
  3226.      (mail-header-lines h2)))
  3227.  
  3228. (defun gnus-thread-sort-by-lines (h1 h2)
  3229.   "Sort threads by root article Lines header."
  3230.   (gnus-article-sort-by-lines
  3231.    (gnus-thread-header h1) (gnus-thread-header h2)))
  3232.  
  3233. (defsubst gnus-article-sort-by-author (h1 h2)
  3234.   "Sort articles by root author."
  3235.   (string-lessp
  3236.    (let ((extract (funcall
  3237.            gnus-extract-address-components
  3238.            (mail-header-from h1))))
  3239.      (or (car extract) (cadr extract) ""))
  3240.    (let ((extract (funcall
  3241.            gnus-extract-address-components
  3242.            (mail-header-from h2))))
  3243.      (or (car extract) (cadr extract) ""))))
  3244.  
  3245. (defun gnus-thread-sort-by-author (h1 h2)
  3246.   "Sort threads by root author."
  3247.   (gnus-article-sort-by-author
  3248.    (gnus-thread-header h1)  (gnus-thread-header h2)))
  3249.  
  3250. (defsubst gnus-article-sort-by-subject (h1 h2)
  3251.   "Sort articles by root subject."
  3252.   (string-lessp
  3253.    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
  3254.    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
  3255.  
  3256. (defun gnus-thread-sort-by-subject (h1 h2)
  3257.   "Sort threads by root subject."
  3258.   (gnus-article-sort-by-subject
  3259.    (gnus-thread-header h1) (gnus-thread-header h2)))
  3260.  
  3261. (defsubst gnus-article-sort-by-date (h1 h2)
  3262.   "Sort articles by root article date."
  3263.   (gnus-time-less
  3264.    (gnus-date-get-time (mail-header-date h1))
  3265.    (gnus-date-get-time (mail-header-date h2))))
  3266.  
  3267. (defun gnus-thread-sort-by-date (h1 h2)
  3268.   "Sort threads by root article date."
  3269.   (gnus-article-sort-by-date
  3270.    (gnus-thread-header h1) (gnus-thread-header h2)))
  3271.  
  3272. (defsubst gnus-article-sort-by-score (h1 h2)
  3273.   "Sort articles by root article score.
  3274. Unscored articles will be counted as having a score of zero."
  3275.   (> (or (cdr (assq (mail-header-number h1)
  3276.             gnus-newsgroup-scored))
  3277.      gnus-summary-default-score 0)
  3278.      (or (cdr (assq (mail-header-number h2)
  3279.             gnus-newsgroup-scored))
  3280.      gnus-summary-default-score 0)))
  3281.  
  3282. (defun gnus-thread-sort-by-score (h1 h2)
  3283.   "Sort threads by root article score."
  3284.   (gnus-article-sort-by-score
  3285.    (gnus-thread-header h1) (gnus-thread-header h2)))
  3286.  
  3287. (defun gnus-thread-sort-by-total-score (h1 h2)
  3288.   "Sort threads by the sum of all scores in the thread.
  3289. Unscored articles will be counted as having a score of zero."
  3290.   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
  3291.  
  3292. (defun gnus-thread-total-score (thread)
  3293.   ;;  This function find the total score of THREAD.
  3294.   (cond ((null thread)
  3295.      0)
  3296.     ((consp thread)
  3297.      (if (stringp (car thread))
  3298.          (apply gnus-thread-score-function 0
  3299.             (mapcar 'gnus-thread-total-score-1 (cdr thread)))
  3300.        (gnus-thread-total-score-1 thread)))
  3301.     (t
  3302.      (gnus-thread-total-score-1 (list thread)))))
  3303.  
  3304. (defun gnus-thread-total-score-1 (root)
  3305.   ;; This function find the total score of the thread below ROOT.
  3306.   (setq root (car root))
  3307.   (apply gnus-thread-score-function
  3308.      (or (append
  3309.           (mapcar 'gnus-thread-total-score
  3310.               (cdr (gnus-gethash (mail-header-id root)
  3311.                      gnus-newsgroup-dependencies)))
  3312.           (when (> (mail-header-number root) 0)
  3313.         (list (or (cdr (assq (mail-header-number root)
  3314.                      gnus-newsgroup-scored))
  3315.               gnus-summary-default-score 0))))
  3316.          (list gnus-summary-default-score)
  3317.          '(0))))
  3318.  
  3319. ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
  3320. (defvar gnus-tmp-prev-subject nil)
  3321. (defvar gnus-tmp-false-parent nil)
  3322. (defvar gnus-tmp-root-expunged nil)
  3323. (defvar gnus-tmp-dummy-line nil)
  3324.  
  3325. (defun gnus-summary-prepare-threads (threads)
  3326.   "Prepare summary buffer from THREADS and indentation LEVEL.
  3327. THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
  3328. or a straight list of headers."
  3329.   (gnus-message 7 "Generating summary...")
  3330.  
  3331.   (setq gnus-newsgroup-threads threads)
  3332.   (beginning-of-line)
  3333.  
  3334.   (let ((gnus-tmp-level 0)
  3335.     (default-score (or gnus-summary-default-score 0))
  3336.     (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
  3337.     thread number subject stack state gnus-tmp-gathered beg-match
  3338.     new-roots gnus-tmp-new-adopts thread-end
  3339.     gnus-tmp-header gnus-tmp-unread
  3340.     gnus-tmp-replied gnus-tmp-subject-or-nil
  3341.     gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
  3342.     gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
  3343.     gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
  3344.  
  3345.     (setq gnus-tmp-prev-subject nil)
  3346.  
  3347.     (if (vectorp (car threads))
  3348.     ;; If this is a straight (sic) list of headers, then a
  3349.     ;; threaded summary display isn't required, so we just create
  3350.     ;; an unthreaded one.
  3351.     (gnus-summary-prepare-unthreaded threads)
  3352.  
  3353.       ;; Do the threaded display.
  3354.  
  3355.       (while (or threads stack gnus-tmp-new-adopts new-roots)
  3356.  
  3357.     (if (and (= gnus-tmp-level 0)
  3358.          (not (setq gnus-tmp-dummy-line nil))
  3359.          (or (not stack)
  3360.              (= (caar stack) 0))
  3361.          (not gnus-tmp-false-parent)
  3362.          (or gnus-tmp-new-adopts new-roots))
  3363.         (if gnus-tmp-new-adopts
  3364.         (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
  3365.               thread (list (car gnus-tmp-new-adopts))
  3366.               gnus-tmp-header (caar thread)
  3367.               gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
  3368.           (when new-roots
  3369.         (setq thread (list (car new-roots))
  3370.               gnus-tmp-header (caar thread)
  3371.               new-roots (cdr new-roots))))
  3372.  
  3373.       (if threads
  3374.           ;; If there are some threads, we do them before the
  3375.           ;; threads on the stack.
  3376.           (setq thread threads
  3377.             gnus-tmp-header (caar thread))
  3378.         ;; There were no current threads, so we pop something off
  3379.         ;; the stack.
  3380.         (setq state (car stack)
  3381.           gnus-tmp-level (car state)
  3382.           thread (cdr state)
  3383.           stack (cdr stack)
  3384.           gnus-tmp-header (caar thread))))
  3385.  
  3386.     (setq gnus-tmp-false-parent nil)
  3387.     (setq gnus-tmp-root-expunged nil)
  3388.     (setq thread-end nil)
  3389.  
  3390.     (if (stringp gnus-tmp-header)
  3391.         ;; The header is a dummy root.
  3392.         (cond
  3393.          ((eq gnus-summary-make-false-root 'adopt)
  3394.           ;; We let the first article adopt the rest.
  3395.           (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
  3396.                            (cddar thread)))
  3397.           (setq gnus-tmp-gathered
  3398.             (nconc (mapcar
  3399.                 (lambda (h) (mail-header-number (car h)))
  3400.                 (cddar thread))
  3401.                gnus-tmp-gathered))
  3402.           (setq thread (cons (list (caar thread)
  3403.                        (cadar thread))
  3404.                  (cdr thread)))
  3405.           (setq gnus-tmp-level -1
  3406.             gnus-tmp-false-parent t))
  3407.          ((eq gnus-summary-make-false-root 'empty)
  3408.           ;; We print adopted articles with empty subject fields.
  3409.           (setq gnus-tmp-gathered
  3410.             (nconc (mapcar
  3411.                 (lambda (h) (mail-header-number (car h)))
  3412.                 (cddar thread))
  3413.                gnus-tmp-gathered))
  3414.           (setq gnus-tmp-level -1))
  3415.          ((eq gnus-summary-make-false-root 'dummy)
  3416.           ;; We remember that we probably want to output a dummy
  3417.           ;; root.
  3418.           (setq gnus-tmp-dummy-line gnus-tmp-header)
  3419.           (setq gnus-tmp-prev-subject gnus-tmp-header))
  3420.          (t
  3421.           ;; We do not make a root for the gathered
  3422.           ;; sub-threads at all.
  3423.           (setq gnus-tmp-level -1)))
  3424.  
  3425.       (setq number (mail-header-number gnus-tmp-header)
  3426.         subject (mail-header-subject gnus-tmp-header))
  3427.  
  3428.       (cond
  3429.        ;; If the thread has changed subject, we might want to make
  3430.        ;; this subthread into a root.
  3431.        ((and (null gnus-thread-ignore-subject)
  3432.          (not (zerop gnus-tmp-level))
  3433.          gnus-tmp-prev-subject
  3434.          (not (inline
  3435.             (gnus-subject-equal gnus-tmp-prev-subject subject))))
  3436.         (setq new-roots (nconc new-roots (list (car thread)))
  3437.           thread-end t
  3438.           gnus-tmp-header nil))
  3439.        ;; If the article lies outside the current limit,
  3440.        ;; then we do not display it.
  3441.        ((not (memq number gnus-newsgroup-limit))
  3442.         (setq gnus-tmp-gathered
  3443.           (nconc (mapcar
  3444.               (lambda (h) (mail-header-number (car h)))
  3445.               (cdar thread))
  3446.              gnus-tmp-gathered))
  3447.         (setq gnus-tmp-new-adopts (if (cdar thread)
  3448.                       (append gnus-tmp-new-adopts
  3449.                           (cdar thread))
  3450.                     gnus-tmp-new-adopts)
  3451.           thread-end t
  3452.           gnus-tmp-header nil)
  3453.         (when (zerop gnus-tmp-level)
  3454.           (setq gnus-tmp-root-expunged t)))
  3455.        ;; Perhaps this article is to be marked as read?
  3456.        ((and gnus-summary-mark-below
  3457.          (< (or (cdr (assq number gnus-newsgroup-scored))
  3458.             default-score)
  3459.             gnus-summary-mark-below)
  3460.          ;; Don't touch sparse articles.
  3461.          (not (gnus-summary-article-sparse-p number))
  3462.          (not (gnus-summary-article-ancient-p number)))
  3463.         (setq gnus-newsgroup-unreads
  3464.           (delq number gnus-newsgroup-unreads))
  3465.         (if gnus-newsgroup-auto-expire
  3466.         (push number gnus-newsgroup-expirable)
  3467.           (push (cons number gnus-low-score-mark)
  3468.             gnus-newsgroup-reads))))
  3469.  
  3470.       (when gnus-tmp-header
  3471.         ;; We may have an old dummy line to output before this
  3472.         ;; article.
  3473.         (when gnus-tmp-dummy-line
  3474.           (gnus-summary-insert-dummy-line
  3475.            gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
  3476.           (setq gnus-tmp-dummy-line nil))
  3477.  
  3478.         ;; Compute the mark.
  3479.         (setq gnus-tmp-unread (gnus-article-mark number))
  3480.  
  3481.         (push (gnus-data-make number gnus-tmp-unread (1+ (point))
  3482.                   gnus-tmp-header gnus-tmp-level)
  3483.           gnus-newsgroup-data)
  3484.  
  3485.         ;; Actually insert the line.
  3486.         (setq
  3487.          gnus-tmp-subject-or-nil
  3488.          (cond
  3489.           ((and gnus-thread-ignore-subject
  3490.             gnus-tmp-prev-subject
  3491.             (not (inline (gnus-subject-equal
  3492.                   gnus-tmp-prev-subject subject))))
  3493.            subject)
  3494.           ((zerop gnus-tmp-level)
  3495.            (if (and (eq gnus-summary-make-false-root 'empty)
  3496.             (memq number gnus-tmp-gathered)
  3497.             gnus-tmp-prev-subject
  3498.             (inline (gnus-subject-equal
  3499.                  gnus-tmp-prev-subject subject)))
  3500.            gnus-summary-same-subject
  3501.          subject))
  3502.           (t gnus-summary-same-subject)))
  3503.         (if (and (eq gnus-summary-make-false-root 'adopt)
  3504.              (= gnus-tmp-level 1)
  3505.              (memq number gnus-tmp-gathered))
  3506.         (setq gnus-tmp-opening-bracket ?\<
  3507.               gnus-tmp-closing-bracket ?\>)
  3508.           (setq gnus-tmp-opening-bracket ?\[
  3509.             gnus-tmp-closing-bracket ?\]))
  3510.         (setq
  3511.          gnus-tmp-indentation
  3512.          (aref gnus-thread-indent-array gnus-tmp-level)
  3513.          gnus-tmp-lines (mail-header-lines gnus-tmp-header)
  3514.          gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
  3515.                 gnus-summary-default-score 0)
  3516.          gnus-tmp-score-char
  3517.          (if (or (null gnus-summary-default-score)
  3518.              (<= (abs (- gnus-tmp-score gnus-summary-default-score))
  3519.              gnus-summary-zcore-fuzz))
  3520.          ? 
  3521.            (if (< gnus-tmp-score gnus-summary-default-score)
  3522.            gnus-score-below-mark gnus-score-over-mark))
  3523.          gnus-tmp-replied
  3524.          (cond ((memq number gnus-newsgroup-processable)
  3525.             gnus-process-mark)
  3526.            ((memq number gnus-newsgroup-cached)
  3527.             gnus-cached-mark)
  3528.            ((memq number gnus-newsgroup-replied)
  3529.             gnus-replied-mark)
  3530.            ((memq number gnus-newsgroup-saved)
  3531.             gnus-saved-mark)
  3532.            (t gnus-unread-mark))
  3533.          gnus-tmp-from (mail-header-from gnus-tmp-header)
  3534.          gnus-tmp-name
  3535.          (cond
  3536.           ((string-match "<[^>]+> *$" gnus-tmp-from)
  3537.            (setq beg-match (match-beginning 0))
  3538.            (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
  3539.             (substring gnus-tmp-from (1+ (match-beginning 0))
  3540.                    (1- (match-end 0))))
  3541.            (substring gnus-tmp-from 0 beg-match)))
  3542.           ((string-match "(.+)" gnus-tmp-from)
  3543.            (substring gnus-tmp-from
  3544.               (1+ (match-beginning 0)) (1- (match-end 0))))
  3545.           (t gnus-tmp-from)))
  3546.         (when (string= gnus-tmp-name "")
  3547.           (setq gnus-tmp-name gnus-tmp-from))
  3548.         (unless (numberp gnus-tmp-lines)
  3549.           (setq gnus-tmp-lines 0))
  3550.         (gnus-put-text-property
  3551.          (point)
  3552.          (progn (eval gnus-summary-line-format-spec) (point))
  3553.          'gnus-number number)
  3554.         (when gnus-visual-p
  3555.           (forward-line -1)
  3556.           (run-hooks 'gnus-summary-update-hook)
  3557.           (forward-line 1))
  3558.  
  3559.         (setq gnus-tmp-prev-subject subject)))
  3560.  
  3561.     (when (nth 1 thread)
  3562.       (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
  3563.     (incf gnus-tmp-level)
  3564.     (setq threads (if thread-end nil (cdar thread)))
  3565.     (unless threads
  3566.       (setq gnus-tmp-level 0)))))
  3567.   (gnus-message 7 "Generating summary...done"))
  3568.  
  3569. (defun gnus-summary-prepare-unthreaded (headers)
  3570.   "Generate an unthreaded summary buffer based on HEADERS."
  3571.   (let (header number mark)
  3572.  
  3573.     (beginning-of-line)
  3574.  
  3575.     (while headers
  3576.       ;; We may have to root out some bad articles...
  3577.       (when (memq (setq number (mail-header-number
  3578.                 (setq header (pop headers))))
  3579.           gnus-newsgroup-limit)
  3580.     ;; Mark article as read when it has a low score.
  3581.     (when (and gnus-summary-mark-below
  3582.            (< (or (cdr (assq number gnus-newsgroup-scored))
  3583.               gnus-summary-default-score 0)
  3584.               gnus-summary-mark-below)
  3585.            (not (gnus-summary-article-ancient-p number)))
  3586.       (setq gnus-newsgroup-unreads
  3587.         (delq number gnus-newsgroup-unreads))
  3588.       (if gnus-newsgroup-auto-expire
  3589.           (push number gnus-newsgroup-expirable)
  3590.         (push (cons number gnus-low-score-mark)
  3591.           gnus-newsgroup-reads)))
  3592.  
  3593.     (setq mark (gnus-article-mark number))
  3594.     (push (gnus-data-make number mark (1+ (point)) header 0)
  3595.           gnus-newsgroup-data)
  3596.     (gnus-summary-insert-line
  3597.      header 0 number
  3598.      mark (memq number gnus-newsgroup-replied)
  3599.      (memq number gnus-newsgroup-expirable)
  3600.      (mail-header-subject header) nil
  3601.      (cdr (assq number gnus-newsgroup-scored))
  3602.      (memq number gnus-newsgroup-processable))))))
  3603.  
  3604. (defun gnus-select-newsgroup (group &optional read-all)
  3605.   "Select newsgroup GROUP.
  3606. If READ-ALL is non-nil, all articles in the group are selected."
  3607.   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
  3608.      ;;!!! Dirty hack; should be removed.
  3609.      (gnus-summary-ignore-duplicates
  3610.       (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
  3611.           t
  3612.         gnus-summary-ignore-duplicates))
  3613.      (info (nth 2 entry))
  3614.      articles fetched-articles cached)
  3615.  
  3616.     (unless (gnus-check-server
  3617.          (setq gnus-current-select-method
  3618.            (gnus-find-method-for-group group)))
  3619.       (error "Couldn't open server"))
  3620.  
  3621.     (or (and entry (not (eq (car entry) t))) ; Either it's active...
  3622.     (gnus-activate-group group)    ; Or we can activate it...
  3623.     (progn                ; Or we bug out.
  3624.       (when (equal major-mode 'gnus-summary-mode)
  3625.         (kill-buffer (current-buffer)))
  3626.       (error "Couldn't request group %s: %s"
  3627.          group (gnus-status-message group))))
  3628.  
  3629.     (unless (gnus-request-group group t)
  3630.       (when (equal major-mode 'gnus-summary-mode)
  3631.     (kill-buffer (current-buffer)))
  3632.       (error "Couldn't request group %s: %s"
  3633.          group (gnus-status-message group)))
  3634.  
  3635.     (setq gnus-newsgroup-name group)
  3636.     (setq gnus-newsgroup-unselected nil)
  3637.     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
  3638.  
  3639.     ;; Adjust and set lists of article marks.
  3640.     (when info
  3641.       (gnus-adjust-marked-articles info))
  3642.  
  3643.     ;; Kludge to avoid having cached articles nixed out in virtual groups.
  3644.     (when (gnus-virtual-group-p group)
  3645.       (setq cached gnus-newsgroup-cached))
  3646.  
  3647.     (setq gnus-newsgroup-unreads
  3648.       (gnus-set-difference
  3649.        (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
  3650.        gnus-newsgroup-dormant))
  3651.  
  3652.     (setq gnus-newsgroup-processable nil)
  3653.  
  3654.     (gnus-update-read-articles group gnus-newsgroup-unreads)
  3655.     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
  3656.       (gnus-group-update-group group))
  3657.  
  3658.     (setq articles (gnus-articles-to-read group read-all))
  3659.  
  3660.     (cond
  3661.      ((null articles)
  3662.       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
  3663.       'quit)
  3664.      ((eq articles 0) nil)
  3665.      (t
  3666.       ;; Init the dependencies hash table.
  3667.       (setq gnus-newsgroup-dependencies
  3668.         (gnus-make-hashtable (length articles)))
  3669.       ;; Retrieve the headers and read them in.
  3670.       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
  3671.       (setq gnus-newsgroup-headers
  3672.         (if (eq 'nov
  3673.             (setq gnus-headers-retrieved-by
  3674.               (gnus-retrieve-headers
  3675.                articles gnus-newsgroup-name
  3676.                ;; We might want to fetch old headers, but
  3677.                ;; not if there is only 1 article.
  3678.                (and gnus-fetch-old-headers
  3679.                 (or (and
  3680.                      (not (eq gnus-fetch-old-headers 'some))
  3681.                      (not (numberp gnus-fetch-old-headers)))
  3682.                     (> (length articles) 1))))))
  3683.         (gnus-get-newsgroup-headers-xover
  3684.          articles nil nil gnus-newsgroup-name t)
  3685.           (gnus-get-newsgroup-headers)))
  3686.       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
  3687.  
  3688.       ;; Kludge to avoid having cached articles nixed out in virtual groups.
  3689.       (when cached
  3690.     (setq gnus-newsgroup-cached cached))
  3691.  
  3692.       ;; Suppress duplicates?
  3693.       (when gnus-suppress-duplicates
  3694.     (gnus-dup-suppress-articles))
  3695.  
  3696.       ;; Set the initial limit.
  3697.       (setq gnus-newsgroup-limit (copy-sequence articles))
  3698.       ;; Remove canceled articles from the list of unread articles.
  3699.       (setq gnus-newsgroup-unreads
  3700.         (gnus-set-sorted-intersection
  3701.          gnus-newsgroup-unreads
  3702.          (setq fetched-articles
  3703.            (mapcar (lambda (headers) (mail-header-number headers))
  3704.                gnus-newsgroup-headers))))
  3705.       ;; Removed marked articles that do not exist.
  3706.       (gnus-update-missing-marks
  3707.        (gnus-sorted-complement fetched-articles articles))
  3708.       ;; We might want to build some more threads first.
  3709.       (and gnus-fetch-old-headers
  3710.        (eq gnus-headers-retrieved-by 'nov)
  3711.        (gnus-build-old-threads))
  3712.       ;; Check whether auto-expire is to be done in this group.
  3713.       (setq gnus-newsgroup-auto-expire
  3714.         (gnus-group-auto-expirable-p group))
  3715.       ;; Set up the article buffer now, if necessary.
  3716.       (unless gnus-single-article-buffer
  3717.     (gnus-article-setup-buffer))
  3718.       ;; First and last article in this newsgroup.
  3719.       (when gnus-newsgroup-headers
  3720.     (setq gnus-newsgroup-begin
  3721.           (mail-header-number (car gnus-newsgroup-headers))
  3722.           gnus-newsgroup-end
  3723.           (mail-header-number
  3724.            (gnus-last-element gnus-newsgroup-headers))))
  3725.       ;; GROUP is successfully selected.
  3726.       (or gnus-newsgroup-headers t)))))
  3727.  
  3728. (defun gnus-articles-to-read (group &optional read-all)
  3729.   ;; Find out what articles the user wants to read.
  3730.   (let* ((articles
  3731.       ;; Select all articles if `read-all' is non-nil, or if there
  3732.       ;; are no unread articles.
  3733.       (if (or read-all
  3734.           (and (zerop (length gnus-newsgroup-marked))
  3735.                (zerop (length gnus-newsgroup-unreads)))
  3736.           (eq (gnus-group-find-parameter group 'display)
  3737.               'all))
  3738.           (gnus-uncompress-range (gnus-active group))
  3739.         (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
  3740.               (copy-sequence gnus-newsgroup-unreads))
  3741.           '<)))
  3742.      (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
  3743.      (scored (length scored-list))
  3744.      (number (length articles))
  3745.      (marked (+ (length gnus-newsgroup-marked)
  3746.             (length gnus-newsgroup-dormant)))
  3747.      (select
  3748.       (cond
  3749.        ((numberp read-all)
  3750.         read-all)
  3751.        (t
  3752.         (condition-case ()
  3753.         (cond
  3754.          ((and (or (<= scored marked) (= scored number))
  3755.                (numberp gnus-large-newsgroup)
  3756.                (> number gnus-large-newsgroup))
  3757.           (let ((input
  3758.              (read-string
  3759.               (format
  3760.                "How many articles from %s (default %d): "
  3761.                (gnus-limit-string gnus-newsgroup-name 35)
  3762.                number))))
  3763.             (if (string-match "^[ \t]*$" input) number input)))
  3764.          ((and (> scored marked) (< scored number)
  3765.                (> (- scored number) 20))
  3766.           (let ((input
  3767.              (read-string
  3768.               (format "%s %s (%d scored, %d total): "
  3769.                   "How many articles from"
  3770.                   group scored number))))
  3771.             (if (string-match "^[ \t]*$" input)
  3772.             number input)))
  3773.          (t number))
  3774.           (quit nil))))))
  3775.     (setq select (if (stringp select) (string-to-number select) select))
  3776.     (if (or (null select) (zerop select))
  3777.     select
  3778.       (if (and (not (zerop scored)) (<= (abs select) scored))
  3779.       (progn
  3780.         (setq articles (sort scored-list '<))
  3781.         (setq number (length articles)))
  3782.     (setq articles (copy-sequence articles)))
  3783.  
  3784.       (when (< (abs select) number)
  3785.     (if (< select 0)
  3786.         ;; Select the N oldest articles.
  3787.         (setcdr (nthcdr (1- (abs select)) articles) nil)
  3788.       ;; Select the N most recent articles.
  3789.       (setq articles (nthcdr (- number select) articles))))
  3790.       (setq gnus-newsgroup-unselected
  3791.         (gnus-sorted-intersection
  3792.          gnus-newsgroup-unreads
  3793.          (gnus-sorted-complement gnus-newsgroup-unreads articles)))
  3794.       articles)))
  3795.  
  3796. (defun gnus-killed-articles (killed articles)
  3797.   (let (out)
  3798.     (while articles
  3799.       (when (inline (gnus-member-of-range (car articles) killed))
  3800.     (push (car articles) out))
  3801.       (setq articles (cdr articles)))
  3802.     out))
  3803.  
  3804. (defun gnus-uncompress-marks (marks)
  3805.   "Uncompress the mark ranges in MARKS."
  3806.   (let ((uncompressed '(score bookmark))
  3807.     out)
  3808.     (while marks
  3809.       (if (memq (caar marks) uncompressed)
  3810.       (push (car marks) out)
  3811.     (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
  3812.       (setq marks (cdr marks)))
  3813.     out))
  3814.  
  3815. (defun gnus-adjust-marked-articles (info)
  3816.   "Set all article lists and remove all marks that are no longer legal."
  3817.   (let* ((marked-lists (gnus-info-marks info))
  3818.      (active (gnus-active (gnus-info-group info)))
  3819.      (min (car active))
  3820.      (max (cdr active))
  3821.      (types gnus-article-mark-lists)
  3822.      (uncompressed '(score bookmark killed))
  3823.      marks var articles article mark)
  3824.  
  3825.     (while marked-lists
  3826.       (setq marks (pop marked-lists))
  3827.       (set (setq var (intern (format "gnus-newsgroup-%s"
  3828.                      (car (rassq (setq mark (car marks))
  3829.                          types)))))
  3830.        (if (memq (car marks) uncompressed) (cdr marks)
  3831.          (gnus-uncompress-range (cdr marks))))
  3832.  
  3833.       (setq articles (symbol-value var))
  3834.  
  3835.       ;; All articles have to be subsets of the active articles.
  3836.       (cond
  3837.        ;; Adjust "simple" lists.
  3838.        ((memq mark '(tick dormant expire reply save))
  3839.     (while articles
  3840.       (when (or (< (setq article (pop articles)) min) (> article max))
  3841.         (set var (delq article (symbol-value var))))))
  3842.        ;; Adjust assocs.
  3843.        ((memq mark uncompressed)
  3844.     (when (not (listp (cdr (symbol-value var))))
  3845.       (set var (list (symbol-value var))))
  3846.     (when (not (listp (cdr articles)))
  3847.       (setq articles (list articles)))
  3848.     (while articles
  3849.       (when (or (not (consp (setq article (pop articles))))
  3850.             (< (car article) min)
  3851.             (> (car article) max))
  3852.         (set var (delq article (symbol-value var))))))))))
  3853.  
  3854. (defun gnus-update-missing-marks (missing)
  3855.   "Go through the list of MISSING articles and remove them mark lists."
  3856.   (when missing
  3857.     (let ((types gnus-article-mark-lists)
  3858.       var m)
  3859.       ;; Go through all types.
  3860.       (while types
  3861.     (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
  3862.     (when (symbol-value var)
  3863.       ;; This list has articles.  So we delete all missing articles
  3864.       ;; from it.
  3865.       (setq m missing)
  3866.       (while m
  3867.         (set var (delq (pop m) (symbol-value var)))))))))
  3868.  
  3869. (defun gnus-update-marks ()
  3870.   "Enter the various lists of marked articles into the newsgroup info list."
  3871.   (let ((types gnus-article-mark-lists)
  3872.     (info (gnus-get-info gnus-newsgroup-name))
  3873.     (uncompressed '(score bookmark killed))
  3874.     type list newmarked symbol)
  3875.     (when info
  3876.       ;; Add all marks lists that are non-nil to the list of marks lists.
  3877.       (while (setq type (pop types))
  3878.     (when (setq list (symbol-value
  3879.               (setq symbol
  3880.                 (intern (format "gnus-newsgroup-%s"
  3881.                         (car type))))))
  3882.  
  3883.       ;; Get rid of the entries of the articles that have the
  3884.       ;; default score.
  3885.       (when (and (eq (cdr type) 'score)
  3886.              gnus-save-score
  3887.              list)
  3888.         (let* ((arts list)
  3889.            (prev (cons nil list))
  3890.            (all prev))
  3891.           (while arts
  3892.         (if (or (not (consp (car arts)))
  3893.             (= (cdar arts) gnus-summary-default-score))
  3894.             (setcdr prev (cdr arts))
  3895.           (setq prev arts))
  3896.         (setq arts (cdr arts)))
  3897.           (setq list (cdr all))))
  3898.  
  3899.       (push (cons (cdr type)
  3900.               (if (memq (cdr type) uncompressed) list
  3901.             (gnus-compress-sequence
  3902.              (set symbol (sort list '<)) t)))
  3903.         newmarked)))
  3904.  
  3905.       ;; Enter these new marks into the info of the group.
  3906.       (if (nthcdr 3 info)
  3907.       (setcar (nthcdr 3 info) newmarked)
  3908.     ;; Add the marks lists to the end of the info.
  3909.     (when newmarked
  3910.       (setcdr (nthcdr 2 info) (list newmarked))))
  3911.  
  3912.       ;; Cut off the end of the info if there's nothing else there.
  3913.       (let ((i 5))
  3914.     (while (and (> i 2)
  3915.             (not (nth i info)))
  3916.       (when (nthcdr (decf i) info)
  3917.         (setcdr (nthcdr i info) nil)))))))
  3918.  
  3919. (defun gnus-set-mode-line (where)
  3920.   "This function sets the mode line of the article or summary buffers.
  3921. If WHERE is `summary', the summary mode line format will be used."
  3922.   ;; Is this mode line one we keep updated?
  3923.   (when (memq where gnus-updated-mode-lines)
  3924.     (let (mode-string)
  3925.       (save-excursion
  3926.     ;; We evaluate this in the summary buffer since these
  3927.     ;; variables are buffer-local to that buffer.
  3928.     (set-buffer gnus-summary-buffer)
  3929.     ;; We bind all these variables that are used in the `eval' form
  3930.     ;; below.
  3931.     (let* ((mformat (symbol-value
  3932.              (intern
  3933.               (format "gnus-%s-mode-line-format-spec" where))))
  3934.            (gnus-tmp-group-name gnus-newsgroup-name)
  3935.            (gnus-tmp-article-number (or gnus-current-article 0))
  3936.            (gnus-tmp-unread gnus-newsgroup-unreads)
  3937.            (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
  3938.            (gnus-tmp-unselected (length gnus-newsgroup-unselected))
  3939.            (gnus-tmp-unread-and-unselected
  3940.         (cond ((and (zerop gnus-tmp-unread-and-unticked)
  3941.                 (zerop gnus-tmp-unselected))
  3942.                "")
  3943.               ((zerop gnus-tmp-unselected)
  3944.                (format "{%d more}" gnus-tmp-unread-and-unticked))
  3945.               (t (format "{%d(+%d) more}"
  3946.                  gnus-tmp-unread-and-unticked
  3947.                  gnus-tmp-unselected))))
  3948.            (gnus-tmp-subject
  3949.         (if (and gnus-current-headers
  3950.              (vectorp gnus-current-headers))
  3951.             (gnus-mode-string-quote
  3952.              (mail-header-subject gnus-current-headers))
  3953.           ""))
  3954.            bufname-length max-len
  3955.            gnus-tmp-header);; passed as argument to any user-format-funcs
  3956.       (setq mode-string (eval mformat))
  3957.       (setq bufname-length (if (string-match "%b" mode-string)
  3958.                    (- (length
  3959.                        (buffer-name
  3960.                     (if (eq where 'summary)
  3961.                         nil
  3962.                       (get-buffer gnus-article-buffer))))
  3963.                       2)
  3964.                  0))
  3965.       (setq max-len (max 4 (if gnus-mode-non-string-length
  3966.                    (- (window-width)
  3967.                       gnus-mode-non-string-length
  3968.                       bufname-length)
  3969.                  (length mode-string))))
  3970.       ;; We might have to chop a bit of the string off...
  3971.       (when (> (length mode-string) max-len)
  3972.         (setq mode-string
  3973.           (concat (gnus-truncate-string mode-string (- max-len 3))
  3974.               "...")))
  3975.       ;; Pad the mode string a bit.
  3976.       (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
  3977.       ;; Update the mode line.
  3978.       (setq mode-line-buffer-identification
  3979.         (gnus-mode-line-buffer-identification (list mode-string)))
  3980.       (set-buffer-modified-p t))))
  3981.  
  3982. (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
  3983.   "Go through the HEADERS list and add all Xrefs to a hash table.
  3984. The resulting hash table is returned, or nil if no Xrefs were found."
  3985.   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
  3986.      (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
  3987.      (xref-hashtb (gnus-make-hashtable))
  3988.      start group entry number xrefs header)
  3989.     (while headers
  3990.       (setq header (pop headers))
  3991.       (when (and (setq xrefs (mail-header-xref header))
  3992.          (not (memq (setq number (mail-header-number header))
  3993.                 unreads)))
  3994.     (setq start 0)
  3995.     (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
  3996.       (setq start (match-end 0))
  3997.       (setq group (if prefix
  3998.               (concat prefix (substring xrefs (match-beginning 1)
  3999.                             (match-end 1)))
  4000.             (substring xrefs (match-beginning 1) (match-end 1))))
  4001.       (setq number
  4002.         (string-to-int (substring xrefs (match-beginning 2)
  4003.                       (match-end 2))))
  4004.       (if (setq entry (gnus-gethash group xref-hashtb))
  4005.           (setcdr entry (cons number (cdr entry)))
  4006.         (gnus-sethash group (cons number nil) xref-hashtb)))))
  4007.     (and start xref-hashtb)))
  4008.  
  4009. (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
  4010.   "Look through all the headers and mark the Xrefs as read."
  4011.   (let ((virtual (gnus-virtual-group-p from-newsgroup))
  4012.     name entry info xref-hashtb idlist method nth4)
  4013.     (save-excursion
  4014.       (set-buffer gnus-group-buffer)
  4015.       (when (setq xref-hashtb
  4016.           (gnus-create-xref-hashtb from-newsgroup headers unreads))
  4017.     (mapatoms
  4018.      (lambda (group)
  4019.        (unless (string= from-newsgroup (setq name (symbol-name group)))
  4020.          (setq idlist (symbol-value group))
  4021.          ;; Dead groups are not updated.
  4022.          (and (prog1
  4023.               (setq entry (gnus-gethash name gnus-newsrc-hashtb)
  4024.                 info (nth 2 entry))
  4025.             (when (stringp (setq nth4 (gnus-info-method info)))
  4026.               (setq nth4 (gnus-server-to-method nth4))))
  4027.           ;; Only do the xrefs if the group has the same
  4028.           ;; select method as the group we have just read.
  4029.           (or (gnus-methods-equal-p
  4030.                nth4 (gnus-find-method-for-group from-newsgroup))
  4031.               virtual
  4032.               (equal nth4 (setq method (gnus-find-method-for-group
  4033.                         from-newsgroup)))
  4034.               (and (equal (car nth4) (car method))
  4035.                (equal (nth 1 nth4) (nth 1 method))))
  4036.           gnus-use-cross-reference
  4037.           (or (not (eq gnus-use-cross-reference t))
  4038.               virtual
  4039.               ;; Only do cross-references on subscribed
  4040.               ;; groups, if that is what is wanted.
  4041.               (<= (gnus-info-level info) gnus-level-subscribed))
  4042.           (gnus-group-make-articles-read name idlist))))
  4043.      xref-hashtb)))))
  4044.  
  4045. (defun gnus-group-make-articles-read (group articles)
  4046.   "Update the info of GROUP to say that ARTICLES are read."
  4047.   (let* ((num 0)
  4048.      (entry (gnus-gethash group gnus-newsrc-hashtb))
  4049.      (info (nth 2 entry))
  4050.      (active (gnus-active group))
  4051.      range)
  4052.     ;; First peel off all illegal article numbers.
  4053.     (when active
  4054.       (let ((ids articles)
  4055.         id first)
  4056.     (while (setq id (pop ids))
  4057.       (when (and first (> id (cdr active)))
  4058.         ;; We'll end up in this situation in one particular
  4059.         ;; obscure situation.  If you re-scan a group and get
  4060.         ;; a new article that is cross-posted to a different
  4061.         ;; group that has not been re-scanned, you might get
  4062.         ;; crossposted article that has a higher number than
  4063.         ;; Gnus believes possible.  So we re-activate this
  4064.         ;; group as well.  This might mean doing the
  4065.         ;; crossposting thingy will *increase* the number
  4066.         ;; of articles in some groups.  Tsk, tsk.
  4067.         (setq active (or (gnus-activate-group group) active)))
  4068.       (when (or (> id (cdr active))
  4069.             (< id (car active)))
  4070.         (setq articles (delq id articles))))))
  4071.     (save-excursion
  4072.       (set-buffer gnus-group-buffer)
  4073.       (gnus-undo-register
  4074.     `(progn
  4075.        (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
  4076.        (gnus-info-set-read ',info ',(gnus-info-read info))
  4077.        (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
  4078.        (gnus-group-update-group ,group t))))
  4079.     ;; If the read list is nil, we init it.
  4080.     (and active
  4081.      (null (gnus-info-read info))
  4082.      (> (car active) 1)
  4083.      (gnus-info-set-read info (cons 1 (1- (car active)))))
  4084.     ;; Then we add the read articles to the range.
  4085.     (gnus-info-set-read
  4086.      info
  4087.      (setq range
  4088.        (gnus-add-to-range
  4089.         (gnus-info-read info) (setq articles (sort articles '<)))))
  4090.     ;; Then we have to re-compute how many unread
  4091.     ;; articles there are in this group.
  4092.     (when active
  4093.       (cond
  4094.        ((not range)
  4095.     (setq num (- (1+ (cdr active)) (car active))))
  4096.        ((not (listp (cdr range)))
  4097.     (setq num (- (cdr active) (- (1+ (cdr range))
  4098.                      (car range)))))
  4099.        (t
  4100.     (while range
  4101.       (if (numberp (car range))
  4102.           (setq num (1+ num))
  4103.         (setq num (+ num (- (1+ (cdar range)) (caar range)))))
  4104.       (setq range (cdr range)))
  4105.     (setq num (- (cdr active) num))))
  4106.       ;; Update the number of unread articles.
  4107.       (setcar entry num)
  4108.       ;; Update the group buffer.
  4109.       (gnus-group-update-group group t))))
  4110.  
  4111. (defun gnus-methods-equal-p (m1 m2)
  4112.   (let ((m1 (or m1 gnus-select-method))
  4113.     (m2 (or m2 gnus-select-method)))
  4114.     (or (equal m1 m2)
  4115.     (and (eq (car m1) (car m2))
  4116.          (or (not (memq 'address (assoc (symbol-name (car m1))
  4117.                         gnus-valid-select-methods)))
  4118.          (equal (nth 1 m1) (nth 1 m2)))))))
  4119.  
  4120. (defvar gnus-newsgroup-none-id 0)
  4121.  
  4122. (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
  4123.   (let ((cur nntp-server-buffer)
  4124.     (dependencies
  4125.      (or dependencies
  4126.          (save-excursion (set-buffer gnus-summary-buffer)
  4127.                  gnus-newsgroup-dependencies)))
  4128.     headers id id-dep ref-dep end ref)
  4129.     (save-excursion
  4130.       (set-buffer nntp-server-buffer)
  4131.       ;; Translate all TAB characters into SPACE characters.
  4132.       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
  4133.       (run-hooks 'gnus-parse-headers-hook)
  4134.       (let ((case-fold-search t)
  4135.         in-reply-to header p lines)
  4136.     (goto-char (point-min))
  4137.     ;; Search to the beginning of the next header.    Error messages
  4138.     ;; do not begin with 2 or 3.
  4139.     (while (re-search-forward "^[23][0-9]+ " nil t)
  4140.       (setq id nil
  4141.         ref nil)
  4142.       ;; This implementation of this function, with nine
  4143.       ;; search-forwards instead of the one re-search-forward and
  4144.       ;; a case (which basically was the old function) is actually
  4145.       ;; about twice as fast, even though it looks messier.     You
  4146.       ;; can't have everything, I guess.  Speed and elegance
  4147.       ;; doesn't always go hand in hand.
  4148.       (setq
  4149.        header
  4150.        (vector
  4151.         ;; Number.
  4152.         (prog1
  4153.         (read cur)
  4154.           (end-of-line)
  4155.           (setq p (point))
  4156.           (narrow-to-region (point)
  4157.                 (or (and (search-forward "\n.\n" nil t)
  4158.                      (- (point) 2))
  4159.                     (point))))
  4160.         ;; Subject.
  4161.         (progn
  4162.           (goto-char p)
  4163.           (if (search-forward "\nsubject: " nil t)
  4164.           ;; 1997/5/4 by MORIOKA Tomohiko <morioka@jaist.ac.jp>
  4165.           (funcall
  4166.            gnus-unstructured-field-decoder (nnheader-header-value))
  4167.         "(none)"))
  4168.         ;; From.
  4169.         (progn
  4170.           (goto-char p)
  4171.           (if (search-forward "\nfrom: " nil t)
  4172.           ;; 1997/5/4 by MORIOKA Tomohiko <morioka@jaist.ac.jp>
  4173.           (funcall
  4174.            gnus-structured-field-decoder (nnheader-header-value))
  4175.         "(nobody)"))
  4176.         ;; Date.
  4177.         (progn
  4178.           (goto-char p)
  4179.           (if (search-forward "\ndate: " nil t)
  4180.           (nnheader-header-value) ""))
  4181.         ;; Message-ID.
  4182.         (progn
  4183.           (goto-char p)
  4184.           (setq id (if (search-forward "\nmessage-id:" nil t)
  4185.                (buffer-substring
  4186.                 (1- (or (search-forward "<" nil t) (point)))
  4187.                 (or (search-forward ">" nil t) (point)))
  4188.              ;; If there was no message-id, we just fake one
  4189.              ;; to make subsequent routines simpler.
  4190.              (nnheader-generate-fake-message-id))))
  4191.         ;; References.
  4192.         (progn
  4193.           (goto-char p)
  4194.           (if (search-forward "\nreferences: " nil t)
  4195.           (progn
  4196.             (setq end (point))
  4197.             (prog1
  4198.             (nnheader-header-value)
  4199.               (setq ref
  4200.                 (buffer-substring
  4201.                  (progn
  4202.                    (end-of-line)
  4203.                    (search-backward ">" end t)
  4204.                    (1+ (point)))
  4205.                  (progn
  4206.                    (search-backward "<" end t)
  4207.                    (point))))))
  4208.         ;; Get the references from the in-reply-to header if there
  4209.         ;; were no references and the in-reply-to header looks
  4210.         ;; promising.
  4211.         (if (and (search-forward "\nin-reply-to: " nil t)
  4212.              (setq in-reply-to (nnheader-header-value))
  4213.              (string-match "<[^>]+>" in-reply-to))
  4214.             (setq ref (substring in-reply-to (match-beginning 0)
  4215.                      (match-end 0)))
  4216.           (setq ref nil))))
  4217.         ;; Chars.
  4218.         0
  4219.         ;; Lines.
  4220.         (progn
  4221.           (goto-char p)
  4222.           (if (search-forward "\nlines: " nil t)
  4223.           (if (numberp (setq lines (ignore-errors (read cur))))
  4224.               lines 0)
  4225.         0))
  4226.         ;; Xref.
  4227.         (progn
  4228.           (goto-char p)
  4229.           (and (search-forward "\nxref: " nil t)
  4230.            (nnheader-header-value)))))
  4231.       (when (equal id ref)
  4232.         (setq ref nil))
  4233.       ;; We do the threading while we read the headers.  The
  4234.       ;; message-id and the last reference are both entered into
  4235.       ;; the same hash table.  Some tippy-toeing around has to be
  4236.       ;; done in case an article has arrived before the article
  4237.       ;; which it refers to.
  4238.       (if (boundp (setq id-dep (intern id dependencies)))
  4239.           (if (and (car (symbol-value id-dep))
  4240.                (not force-new))
  4241.           ;; An article with this Message-ID has already been seen.
  4242.           (if gnus-summary-ignore-duplicates
  4243.               ;; We ignore this one, except we add
  4244.               ;; any additional Xrefs (in case the two articles
  4245.               ;; came from different servers).
  4246.               (progn
  4247.             (mail-header-set-xref
  4248.              (car (symbol-value id-dep))
  4249.              (concat (or (mail-header-xref
  4250.                       (car (symbol-value id-dep)))
  4251.                      "")
  4252.                  (or (mail-header-xref header) "")))
  4253.             (setq header nil))
  4254.             ;; We rename the Message-ID.
  4255.             (set
  4256.              (setq id-dep (intern (setq id (nnmail-message-id))
  4257.                       dependencies))
  4258.              (list header))
  4259.             (mail-header-set-id header id))
  4260.         (setcar (symbol-value id-dep) header))
  4261.         (set id-dep (list header)))
  4262.       (when  header
  4263.         (if (boundp (setq ref-dep (intern (or ref "none") dependencies)))
  4264.         (setcdr (symbol-value ref-dep)
  4265.             (nconc (cdr (symbol-value ref-dep))
  4266.                    (list (symbol-value id-dep))))
  4267.           (set ref-dep (list nil (symbol-value id-dep))))
  4268.         (push header headers))
  4269.       (goto-char (point-max))
  4270.       (widen))
  4271.     (nreverse headers)))))
  4272.  
  4273. ;; The following macros and functions were written by Felix Lee
  4274. ;; <flee@cse.psu.edu>.
  4275.  
  4276. (defmacro gnus-nov-read-integer ()
  4277.   '(prog1
  4278.        (if (= (following-char) ?\t)
  4279.        0
  4280.      (let ((num (ignore-errors (read buffer))))
  4281.        (if (numberp num) num 0)))
  4282.      (unless (eobp)
  4283.        (forward-char 1))))
  4284.  
  4285. (defmacro gnus-nov-skip-field ()
  4286.   '(search-forward "\t" eol 'move))
  4287.  
  4288. (defmacro gnus-nov-field ()
  4289.   '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
  4290.  
  4291. ;; (defvar gnus-nov-none-counter 0)
  4292.  
  4293. ;; This function has to be called with point after the article number
  4294. ;; on the beginning of the line.
  4295. (defun gnus-nov-parse-line (number dependencies &optional force-new)
  4296.   (let ((eol (gnus-point-at-eol))
  4297.     (buffer (current-buffer))
  4298.     header ref id id-dep ref-dep)
  4299.  
  4300.     ;; overview: [num subject from date id refs chars lines misc]
  4301.     (unwind-protect
  4302.     (progn
  4303.       (narrow-to-region (point) eol)
  4304.       (unless (eobp)
  4305.         (forward-char))
  4306.  
  4307.       (setq header
  4308.         (vector
  4309.          number            ; number
  4310.          ;; 1997/5/4 by MORIOKA Tomohiko <morioka@jaist.ac.jp>
  4311.          (funcall
  4312.           gnus-unstructured-field-decoder (gnus-nov-field)) ; subject
  4313.          (funcall
  4314.           gnus-structured-field-decoder (gnus-nov-field))   ; from
  4315.          (gnus-nov-field)    ; date
  4316.          (setq id (or (gnus-nov-field)
  4317.                   (nnheader-generate-fake-message-id))) ; id
  4318.          (progn
  4319.            (let ((beg (point)))
  4320.              (search-forward "\t" eol)
  4321.              (if (search-backward ">" beg t)
  4322.              (setq ref
  4323.                    (buffer-substring
  4324.                 (1+ (point))
  4325.                 (search-backward "<" beg t)))
  4326.                (setq ref nil))
  4327.              (goto-char beg))
  4328.            (gnus-nov-field))    ; refs
  4329.          (gnus-nov-read-integer) ; chars
  4330.          (gnus-nov-read-integer) ; lines
  4331.          (if (= (following-char) ?\n)
  4332.              nil
  4333.            (gnus-nov-field)))))    ; misc
  4334.  
  4335.       (widen))
  4336.  
  4337.     ;; We build the thread tree.
  4338.     (when (equal id ref)
  4339.       ;; This article refers back to itself.  Naughty, naughty.
  4340.       (setq ref nil))
  4341.     (if (boundp (setq id-dep (intern id dependencies)))
  4342.     (if (and (car (symbol-value id-dep))
  4343.          (not force-new))
  4344.         ;; An article with this Message-ID has already been seen.
  4345.         (if gnus-summary-ignore-duplicates
  4346.         ;; We ignore this one, except we add any additional
  4347.         ;; Xrefs (in case the two articles came from different
  4348.         ;; servers.
  4349.         (progn
  4350.           (mail-header-set-xref
  4351.            (car (symbol-value id-dep))
  4352.            (concat (or (mail-header-xref
  4353.                 (car (symbol-value id-dep)))
  4354.                    "")
  4355.                (or (mail-header-xref header) "")))
  4356.           (setq header nil))
  4357.           ;; We rename the Message-ID.
  4358.           (set
  4359.            (setq id-dep (intern (setq id (nnmail-message-id))
  4360.                     dependencies))
  4361.            (list header))
  4362.           (mail-header-set-id header id))
  4363.       (setcar (symbol-value id-dep) header))
  4364.       (set id-dep (list header)))
  4365.     (when header
  4366.       (if (boundp (setq ref-dep (intern (or ref "none") dependencies)))
  4367.       (setcdr (symbol-value ref-dep)
  4368.           (nconc (cdr (symbol-value ref-dep))
  4369.              (list (symbol-value id-dep))))
  4370.     (set ref-dep (list nil (symbol-value id-dep)))))
  4371.     header))
  4372.  
  4373. ;; Goes through the xover lines and returns a list of vectors
  4374. (defun gnus-get-newsgroup-headers-xover (sequence &optional
  4375.                           force-new dependencies
  4376.                           group also-fetch-heads)
  4377.   "Parse the news overview data in the server buffer, and return a
  4378. list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
  4379.   ;; Get the Xref when the users reads the articles since most/some
  4380.   ;; NNTP servers do not include Xrefs when using XOVER.
  4381.   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
  4382.   (let ((cur nntp-server-buffer)
  4383.     (dependencies (or dependencies gnus-newsgroup-dependencies))
  4384.     number headers header)
  4385.     (save-excursion
  4386.       (set-buffer nntp-server-buffer)
  4387.       ;; Allow the user to mangle the headers before parsing them.
  4388.       (run-hooks 'gnus-parse-headers-hook)
  4389.       (goto-char (point-min))
  4390.       (while (not (eobp))
  4391.     (condition-case ()
  4392.         (while (and sequence (not (eobp)))
  4393.           (setq number (read cur))
  4394.           (while (and sequence
  4395.               (< (car sequence) number))
  4396.         (setq sequence (cdr sequence)))
  4397.           (and sequence
  4398.            (eq number (car sequence))
  4399.            (progn
  4400.              (setq sequence (cdr sequence))
  4401.              (setq header (inline
  4402.                     (gnus-nov-parse-line
  4403.                      number dependencies force-new))))
  4404.            (push header headers))
  4405.           (forward-line 1))
  4406.       (error
  4407.        (gnus-error 4 "Strange nov line (%d)"
  4408.                (count-lines (point-min) (point)))))
  4409.     (forward-line 1))
  4410.       ;; A common bug in inn is that if you have posted an article and
  4411.       ;; then retrieves the active file, it will answer correctly --
  4412.       ;; the new article is included.  However, a NOV entry for the
  4413.       ;; article may not have been generated yet, so this may fail.
  4414.       ;; We work around this problem by retrieving the last few
  4415.       ;; headers using HEAD.
  4416.       (if (or (not also-fetch-heads)
  4417.           (not sequence))
  4418.       ;; We (probably) got all the headers.
  4419.       (nreverse headers)
  4420.     (let ((gnus-nov-is-evil t))
  4421.       (nconc
  4422.        (nreverse headers)
  4423.        (when (gnus-retrieve-headers sequence group)
  4424.          (gnus-get-newsgroup-headers))))))))
  4425.  
  4426. (defun gnus-article-get-xrefs ()
  4427.   "Fill in the Xref value in `gnus-current-headers', if necessary.
  4428. This is meant to be called in `gnus-article-internal-prepare-hook'."
  4429.   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
  4430.                  gnus-current-headers)))
  4431.     (or (not gnus-use-cross-reference)
  4432.     (not headers)
  4433.     (and (mail-header-xref headers)
  4434.          (not (string= (mail-header-xref headers) "")))
  4435.     (let ((case-fold-search t)
  4436.           xref)
  4437.       (save-restriction
  4438.         (nnheader-narrow-to-headers)
  4439.         (goto-char (point-min))
  4440.         (when (or (and (eq (downcase (following-char)) ?x)
  4441.                (looking-at "Xref:"))
  4442.               (search-forward "\nXref:" nil t))
  4443.           (goto-char (1+ (match-end 0)))
  4444.           (setq xref (buffer-substring (point)
  4445.                        (progn (end-of-line) (point))))
  4446.           (mail-header-set-xref headers xref)))))))
  4447.  
  4448. (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
  4449.   "Find article ID and insert the summary line for that article."
  4450.   (let ((header (if (and old-header use-old-header)
  4451.             old-header (gnus-read-header id)))
  4452.     (number (and (numberp id) id))
  4453.     pos d)
  4454.     (when header
  4455.       ;; Rebuild the thread that this article is part of and go to the
  4456.       ;; article we have fetched.
  4457.       (when (and (not gnus-show-threads)
  4458.          old-header)
  4459.     (when (setq d (gnus-data-find (mail-header-number old-header)))
  4460.       (goto-char (gnus-data-pos d))
  4461.       (gnus-data-remove
  4462.        number
  4463.        (- (gnus-point-at-bol)
  4464.           (prog1
  4465.           (1+ (gnus-point-at-eol))
  4466.         (gnus-delete-line))))))
  4467.       (when old-header
  4468.     (mail-header-set-number header (mail-header-number old-header)))
  4469.       (setq gnus-newsgroup-sparse
  4470.         (delq (setq number (mail-header-number header))
  4471.           gnus-newsgroup-sparse))
  4472.       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
  4473.       (gnus-rebuild-thread (mail-header-id header))
  4474.       (gnus-summary-goto-subject number nil t))
  4475.     (when (and (numberp number)
  4476.            (> number 0))
  4477.       ;; We have to update the boundaries even if we can't fetch the
  4478.       ;; article if ID is a number -- so that the next `P' or `N'
  4479.       ;; command will fetch the previous (or next) article even
  4480.       ;; if the one we tried to fetch this time has been canceled.
  4481.       (when (> number gnus-newsgroup-end)
  4482.     (setq gnus-newsgroup-end number))
  4483.       (when (< number gnus-newsgroup-begin)
  4484.     (setq gnus-newsgroup-begin number))
  4485.       (setq gnus-newsgroup-unselected
  4486.         (delq number gnus-newsgroup-unselected)))
  4487.     ;; Report back a success?
  4488.     (and header (mail-header-number header))))
  4489.  
  4490. ;;; Process/prefix in the summary buffer
  4491.  
  4492. (defun gnus-summary-work-articles (n)
  4493.   "Return a list of articles to be worked upon.     The prefix argument,
  4494. the list of process marked articles, and the current article will be
  4495. taken into consideration."
  4496.   (cond
  4497.    (n
  4498.     ;; A numerical prefix has been given.
  4499.     (setq n (prefix-numeric-value n))
  4500.     (let ((backward (< n 0))
  4501.       (n (abs (prefix-numeric-value n)))
  4502.       articles article)
  4503.       (save-excursion
  4504.     (while
  4505.         (and (> n 0)
  4506.          (push (setq article (gnus-summary-article-number))
  4507.                articles)
  4508.          (if backward
  4509.              (gnus-summary-find-prev nil article)
  4510.            (gnus-summary-find-next nil article)))
  4511.       (decf n)))
  4512.       (nreverse articles)))
  4513.    ((gnus-region-active-p)
  4514.     ;; Work on the region between point and mark.
  4515.     (let ((max (max (point) (mark)))
  4516.       articles article)
  4517.       (save-excursion
  4518.     (goto-char (min (point) (mark)))
  4519.     (while
  4520.         (and
  4521.          (push (setq article (gnus-summary-article-number)) articles)
  4522.          (gnus-summary-find-next nil article)
  4523.          (< (point) max)))
  4524.     (nreverse articles))))
  4525.    (gnus-newsgroup-processable
  4526.     ;; There are process-marked articles present.
  4527.     ;; Save current state.
  4528.     (gnus-summary-save-process-mark)
  4529.     ;; Return the list.
  4530.     (reverse gnus-newsgroup-processable))
  4531.    (t
  4532.     ;; Just return the current article.
  4533.     (list (gnus-summary-article-number)))))
  4534.  
  4535. (defun gnus-summary-save-process-mark ()
  4536.   "Push the current set of process marked articles on the stack."
  4537.   (interactive)
  4538.   (push (copy-sequence gnus-newsgroup-processable)
  4539.     gnus-newsgroup-process-stack))
  4540.  
  4541. (defun gnus-summary-kill-process-mark ()
  4542.   "Push the current set of process marked articles on the stack and unmark."
  4543.   (interactive)
  4544.   (gnus-summary-save-process-mark)
  4545.   (gnus-summary-unmark-all-processable))
  4546.  
  4547. (defun gnus-summary-yank-process-mark ()
  4548.   "Pop the last process mark state off the stack and restore it."
  4549.   (interactive)
  4550.   (unless gnus-newsgroup-process-stack
  4551.     (error "Empty mark stack"))
  4552.   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
  4553.  
  4554. (defun gnus-summary-process-mark-set (set)
  4555.   "Make SET into the current process marked articles."
  4556.   (gnus-summary-unmark-all-processable)
  4557.   (while set
  4558.     (gnus-summary-set-process-mark (pop set))))
  4559.  
  4560. ;;; Searching and stuff
  4561.  
  4562. (defun gnus-summary-search-group (&optional backward use-level)
  4563.   "Search for next unread newsgroup.
  4564. If optional argument BACKWARD is non-nil, search backward instead."
  4565.   (save-excursion
  4566.     (set-buffer gnus-group-buffer)
  4567.     (when (gnus-group-search-forward
  4568.        backward nil (if use-level (gnus-group-group-level) nil))
  4569.       (gnus-group-group-name))))
  4570.  
  4571. (defun gnus-summary-best-group (&optional exclude-group)
  4572.   "Find the name of the best unread group.
  4573. If EXCLUDE-GROUP, do not go to this group."
  4574.   (save-excursion
  4575.     (set-buffer gnus-group-buffer)
  4576.     (save-excursion
  4577.       (gnus-group-best-unread-group exclude-group))))
  4578.  
  4579. (defun gnus-summary-find-next (&optional unread article backward)
  4580.   (if backward (gnus-summary-find-prev)
  4581.     (let* ((dummy (gnus-summary-article-intangible-p))
  4582.        (article (or article (gnus-summary-article-number)))
  4583.        (arts (gnus-data-find-list article))
  4584.        result)
  4585.       (when (and (not dummy)
  4586.          (or (not gnus-summary-check-current)
  4587.              (not unread)
  4588.              (not (gnus-data-unread-p (car arts)))))
  4589.     (setq arts (cdr arts)))
  4590.       (when (setq result
  4591.           (if unread
  4592.               (progn
  4593.             (while arts
  4594.               (when (gnus-data-unread-p (car arts))
  4595.                 (setq result (car arts)
  4596.                   arts nil))
  4597.               (setq arts (cdr arts)))
  4598.             result)
  4599.             (car arts)))
  4600.     (goto-char (gnus-data-pos result))
  4601.     (gnus-data-number result)))))
  4602.  
  4603. (defun gnus-summary-find-prev (&optional unread article)
  4604.   (let* ((eobp (eobp))
  4605.      (article (or article (gnus-summary-article-number)))
  4606.      (arts (gnus-data-find-list article (gnus-data-list 'rev)))
  4607.      result)
  4608.     (when (and (not eobp)
  4609.            (or (not gnus-summary-check-current)
  4610.            (not unread)
  4611.            (not (gnus-data-unread-p (car arts)))))
  4612.       (setq arts (cdr arts)))
  4613.     (when (setq result
  4614.         (if unread
  4615.             (progn
  4616.               (while arts
  4617.             (when (gnus-data-unread-p (car arts))
  4618.               (setq result (car arts)
  4619.                 arts nil))
  4620.             (setq arts (cdr arts)))
  4621.               result)
  4622.           (car arts)))
  4623.       (goto-char (gnus-data-pos result))
  4624.       (gnus-data-number result))))
  4625.  
  4626. (defun gnus-summary-find-subject (subject &optional unread backward article)
  4627.   (let* ((simp-subject (gnus-simplify-subject-fully subject))
  4628.      (article (or article (gnus-summary-article-number)))
  4629.      (articles (gnus-data-list backward))
  4630.      (arts (gnus-data-find-list article articles))
  4631.      result)
  4632.     (when (or (not gnus-summary-check-current)
  4633.           (not unread)
  4634.           (not (gnus-data-unread-p (car arts))))
  4635.       (setq arts (cdr arts)))
  4636.     (while arts
  4637.       (and (or (not unread)
  4638.            (gnus-data-unread-p (car arts)))
  4639.        (vectorp (gnus-data-header (car arts)))
  4640.        (gnus-subject-equal
  4641.         simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
  4642.        (setq result (car arts)
  4643.          arts nil))
  4644.       (setq arts (cdr arts)))
  4645.     (and result
  4646.      (goto-char (gnus-data-pos result))
  4647.      (gnus-data-number result))))
  4648.  
  4649. (defun gnus-summary-search-forward (&optional unread subject backward)
  4650.   "Search forward for an article.
  4651. If UNREAD, look for unread articles.  If SUBJECT, look for
  4652. articles with that subject.  If BACKWARD, search backward instead."
  4653.   (cond (subject (gnus-summary-find-subject subject unread backward))
  4654.     (backward (gnus-summary-find-prev unread))
  4655.     (t (gnus-summary-find-next unread))))
  4656.  
  4657. (defun gnus-recenter (&optional n)
  4658.   "Center point in window and redisplay frame.
  4659. Also do horizontal recentering."
  4660.   (interactive "P")
  4661.   (when (and gnus-auto-center-summary
  4662.          (not (eq gnus-auto-center-summary 'vertical)))
  4663.     (gnus-horizontal-recenter))
  4664.   (recenter n))
  4665.  
  4666. (defun gnus-summary-recenter ()
  4667.   "Center point in the summary window.
  4668. If `gnus-auto-center-summary' is nil, or the article buffer isn't
  4669. displayed, no centering will be performed."
  4670.   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
  4671.   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
  4672.   (let* ((top (cond ((< (window-height) 4) 0)
  4673.             ((< (window-height) 7) 1)
  4674.             (t 2)))
  4675.      (height (1- (window-height)))
  4676.      (bottom (save-excursion (goto-char (point-max))
  4677.                  (forward-line (- height))
  4678.                  (point)))
  4679.      (window (get-buffer-window (current-buffer))))
  4680.     ;; The user has to want it.
  4681.     (when gnus-auto-center-summary
  4682.       (when (get-buffer-window gnus-article-buffer)
  4683.     ;; Only do recentering when the article buffer is displayed,
  4684.     ;; Set the window start to either `bottom', which is the biggest
  4685.     ;; possible valid number, or the second line from the top,
  4686.     ;; whichever is the least.
  4687.     (set-window-start
  4688.      window (min bottom (save-excursion
  4689.                   (forward-line (- top)) (point)))))
  4690.       ;; Do horizontal recentering while we're at it.
  4691.       (when (and (get-buffer-window (current-buffer) t)
  4692.          (not (eq gnus-auto-center-summary 'vertical)))
  4693.     (let ((selected (selected-window)))
  4694.       (select-window (get-buffer-window (current-buffer) t))
  4695.       (gnus-summary-position-point)
  4696.       (gnus-horizontal-recenter)
  4697.       (select-window selected))))))
  4698.  
  4699. (defun gnus-summary-jump-to-group (newsgroup)
  4700.   "Move point to NEWSGROUP in group mode buffer."
  4701.   ;; Keep update point of group mode buffer if visible.
  4702.   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
  4703.       (save-window-excursion
  4704.     ;; Take care of tree window mode.
  4705.     (when (get-buffer-window gnus-group-buffer)
  4706.       (pop-to-buffer gnus-group-buffer))
  4707.     (gnus-group-jump-to-group newsgroup))
  4708.     (save-excursion
  4709.       ;; Take care of tree window mode.
  4710.       (if (get-buffer-window gnus-group-buffer)
  4711.       (pop-to-buffer gnus-group-buffer)
  4712.     (set-buffer gnus-group-buffer))
  4713.       (gnus-group-jump-to-group newsgroup))))
  4714.  
  4715. ;; This function returns a list of article numbers based on the
  4716. ;; difference between the ranges of read articles in this group and
  4717. ;; the range of active articles.
  4718. (defun gnus-list-of-unread-articles (group)
  4719.   (let* ((read (gnus-info-read (gnus-get-info group)))
  4720.      (active (or (gnus-active group) (gnus-activate-group group)))
  4721.      (last (cdr active))
  4722.      first nlast unread)
  4723.     ;; If none are read, then all are unread.
  4724.     (if (not read)
  4725.     (setq first (car active))
  4726.       ;; If the range of read articles is a single range, then the
  4727.       ;; first unread article is the article after the last read
  4728.       ;; article.  Sounds logical, doesn't it?
  4729.       (if (not (listp (cdr read)))
  4730.       (setq first (1+ (cdr read)))
  4731.     ;; `read' is a list of ranges.
  4732.     (when (/= (setq nlast (or (and (numberp (car read)) (car read))
  4733.                   (caar read)))
  4734.           1)
  4735.       (setq first 1))
  4736.     (while read
  4737.       (when first
  4738.         (while (< first nlast)
  4739.           (push first unread)
  4740.           (setq first (1+ first))))
  4741.       (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
  4742.       (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
  4743.       (setq read (cdr read)))))
  4744.     ;; And add the last unread articles.
  4745.     (while (<= first last)
  4746.       (push first unread)
  4747.       (setq first (1+ first)))
  4748.     ;; Return the list of unread articles.
  4749.     (nreverse unread)))
  4750.  
  4751. (defun gnus-list-of-read-articles (group)
  4752.   "Return a list of unread, unticked and non-dormant articles."
  4753.   (let* ((info (gnus-get-info group))
  4754.      (marked (gnus-info-marks info))
  4755.      (active (gnus-active group)))
  4756.     (and info active
  4757.      (gnus-set-difference
  4758.       (gnus-sorted-complement
  4759.        (gnus-uncompress-range active)
  4760.        (gnus-list-of-unread-articles group))
  4761.       (append
  4762.        (gnus-uncompress-range (cdr (assq 'dormant marked)))
  4763.        (gnus-uncompress-range (cdr (assq 'tick marked))))))))
  4764.  
  4765. ;; Various summary commands
  4766.  
  4767. (defun gnus-summary-universal-argument (arg)
  4768.   "Perform any operation on all articles that are process/prefixed."
  4769.   (interactive "P")
  4770.   (gnus-set-global-variables)
  4771.   (let ((articles (gnus-summary-work-articles arg))
  4772.     func article)
  4773.     (if (eq
  4774.      (setq
  4775.       func
  4776.       (key-binding
  4777.        (read-key-sequence
  4778.         (substitute-command-keys
  4779.          "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"
  4780.          ))))
  4781.      'undefined)
  4782.     (gnus-error 1 "Undefined key")
  4783.       (save-excursion
  4784.     (while articles
  4785.       (gnus-summary-goto-subject (setq article (pop articles)))
  4786.       (let (gnus-newsgroup-processable)
  4787.         (command-execute func))
  4788.       (gnus-summary-remove-process-mark article)))))
  4789.   (gnus-summary-position-point))
  4790.  
  4791. (defun gnus-summary-toggle-truncation (&optional arg)
  4792.   "Toggle truncation of summary lines.
  4793. With arg, turn line truncation on iff arg is positive."
  4794.   (interactive "P")
  4795.   (setq truncate-lines
  4796.     (if (null arg) (not truncate-lines)
  4797.       (> (prefix-numeric-value arg) 0)))
  4798.   (redraw-display))
  4799.  
  4800. (defun gnus-summary-reselect-current-group (&optional all rescan)
  4801.   "Exit and then reselect the current newsgroup.
  4802. The prefix argument ALL means to select all articles."
  4803.   (interactive "P")
  4804.   (gnus-set-global-variables)
  4805.   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
  4806.     (error "Ephemeral groups can't be reselected"))
  4807.   (let ((current-subject (gnus-summary-article-number))
  4808.     (group gnus-newsgroup-name))
  4809.     (setq gnus-newsgroup-begin nil)
  4810.     (gnus-summary-exit)
  4811.     ;; We have to adjust the point of group mode buffer because
  4812.     ;; point was moved to the next unread newsgroup by exiting.
  4813.     (gnus-summary-jump-to-group group)
  4814.     (when rescan
  4815.       (save-excursion
  4816.     (gnus-group-get-new-news-this-group 1)))
  4817.     (gnus-group-read-group all t)
  4818.     (gnus-summary-goto-subject current-subject nil t)))
  4819.  
  4820. (defun gnus-summary-rescan-group (&optional all)
  4821.   "Exit the newsgroup, ask for new articles, and select the newsgroup."
  4822.   (interactive "P")
  4823.   (gnus-summary-reselect-current-group all t))
  4824.  
  4825. (defun gnus-summary-update-info (&optional non-destructive)
  4826.   (save-excursion
  4827.     (let ((group gnus-newsgroup-name))
  4828.       (when gnus-newsgroup-kill-headers
  4829.     (setq gnus-newsgroup-killed
  4830.           (gnus-compress-sequence
  4831.            (nconc
  4832.         (gnus-set-sorted-intersection
  4833.          (gnus-uncompress-range gnus-newsgroup-killed)
  4834.          (setq gnus-newsgroup-unselected
  4835.                (sort gnus-newsgroup-unselected '<)))
  4836.         (setq gnus-newsgroup-unreads
  4837.               (sort gnus-newsgroup-unreads '<)))
  4838.            t)))
  4839.       (unless (listp (cdr gnus-newsgroup-killed))
  4840.     (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
  4841.       (let ((headers gnus-newsgroup-headers))
  4842.     (when (and (not gnus-save-score)
  4843.            (not non-destructive))
  4844.       (setq gnus-newsgroup-scored nil))
  4845.     ;; Set the new ranges of read articles.
  4846.     (save-excursion
  4847.       (set-buffer gnus-group-buffer)
  4848.       (gnus-undo-force-boundary))
  4849.     (gnus-update-read-articles
  4850.      group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
  4851.     ;; Set the current article marks.
  4852.     (gnus-update-marks)
  4853.     ;; Do the cross-ref thing.
  4854.     (when gnus-use-cross-reference
  4855.       (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
  4856.     ;; Do adaptive scoring, and possibly save score files.
  4857.     (when gnus-newsgroup-adaptive
  4858.       (gnus-score-adaptive))
  4859.     (when gnus-use-scoring
  4860.       (gnus-score-save))
  4861.     ;; Do not switch windows but change the buffer to work.
  4862.     (set-buffer gnus-group-buffer)
  4863.     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
  4864.       (gnus-group-update-group group))))))
  4865.  
  4866. (defun gnus-summary-save-newsrc (&optional force)
  4867.   "Save the current number of read/marked articles in the dribble buffer.
  4868. The dribble buffer will then be saved.
  4869. If FORCE (the prefix), also save the .newsrc file(s)."
  4870.   (interactive "P")
  4871.   (gnus-summary-update-info t)
  4872.   (if force
  4873.       (gnus-save-newsrc-file)
  4874.     (gnus-dribble-save)))
  4875.  
  4876. (defun gnus-summary-exit (&optional temporary)
  4877.   "Exit reading current newsgroup, and then return to group selection mode.
  4878. gnus-exit-group-hook is called with no arguments if that value is non-nil."
  4879.   (interactive)
  4880.   (gnus-set-global-variables)
  4881.   (gnus-kill-save-kill-buffer)
  4882.   (let* ((group gnus-newsgroup-name)
  4883.      (quit-config (gnus-group-quit-config gnus-newsgroup-name))
  4884.      (mode major-mode)
  4885.          (group-point nil)
  4886.      (buf (current-buffer)))
  4887.     (run-hooks 'gnus-summary-prepare-exit-hook)
  4888.     ;; If we have several article buffers, we kill them at exit.
  4889.     (unless gnus-single-article-buffer
  4890.       (gnus-kill-buffer gnus-original-article-buffer)
  4891.       (setq gnus-article-current nil))
  4892.     (when gnus-use-cache
  4893.       (gnus-cache-possibly-remove-articles)
  4894.       (gnus-cache-save-buffers))
  4895.     (gnus-async-prefetch-remove-group group)
  4896.     (when gnus-suppress-duplicates
  4897.       (gnus-dup-enter-articles))
  4898.     (when gnus-use-trees
  4899.       (gnus-tree-close group))
  4900.     ;; Make all changes in this group permanent.
  4901.     (unless quit-config
  4902.       (run-hooks 'gnus-exit-group-hook)
  4903.       (gnus-summary-update-info))
  4904.     (gnus-close-group group)
  4905.     ;; Make sure where we were, and go to next newsgroup.
  4906.     (set-buffer gnus-group-buffer)
  4907.     (unless quit-config
  4908.       (gnus-group-jump-to-group group))
  4909.     (run-hooks 'gnus-summary-exit-hook)
  4910.     (unless quit-config
  4911.       (gnus-group-next-unread-group 1))
  4912.     (setq group-point (point))
  4913.     (if temporary
  4914.     nil                ;Nothing to do.
  4915.       ;; If we have several article buffers, we kill them at exit.
  4916.       (unless gnus-single-article-buffer
  4917.     (gnus-kill-buffer gnus-article-buffer)
  4918.     (gnus-kill-buffer gnus-original-article-buffer)
  4919.     (setq gnus-article-current nil))
  4920.       (set-buffer buf)
  4921.       (if (not gnus-kill-summary-on-exit)
  4922.       (gnus-deaden-summary)
  4923.     ;; We set all buffer-local variables to nil.  It is unclear why
  4924.     ;; this is needed, but if we don't, buffer-local variables are
  4925.     ;; not garbage-collected, it seems.  This would the lead to en
  4926.     ;; ever-growing Emacs.
  4927.     (gnus-summary-clear-local-variables)
  4928.     (when (get-buffer gnus-article-buffer)
  4929.       (bury-buffer gnus-article-buffer))
  4930.     ;; We clear the global counterparts of the buffer-local
  4931.     ;; variables as well, just to be on the safe side.
  4932.     (set-buffer gnus-group-buffer)
  4933.     (gnus-summary-clear-local-variables)
  4934.     ;; Return to group mode buffer.
  4935.     (when (eq mode 'gnus-summary-mode)
  4936.       (gnus-kill-buffer buf)))
  4937.       (setq gnus-current-select-method gnus-select-method)
  4938.       (pop-to-buffer gnus-group-buffer)
  4939.       ;; Clear the current group name.
  4940.       (if (not quit-config)
  4941.       (progn
  4942.         (goto-char group-point)
  4943.         (gnus-configure-windows 'group 'force))
  4944.     (gnus-handle-ephemeral-exit quit-config))
  4945.       (unless quit-config
  4946.     (setq gnus-newsgroup-name nil)))))
  4947.  
  4948. (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
  4949. (defun gnus-summary-exit-no-update (&optional no-questions)
  4950.   "Quit reading current newsgroup without updating read article info."
  4951.   (interactive)
  4952.   (gnus-set-global-variables)
  4953.   (let* ((group gnus-newsgroup-name)
  4954.      (quit-config (gnus-group-quit-config group)))
  4955.     (when (or no-questions
  4956.           gnus-expert-user
  4957.           (gnus-y-or-n-p "Discard changes to this group and exit? "))
  4958.       ;; If we have several article buffers, we kill them at exit.
  4959.       (unless gnus-single-article-buffer
  4960.     (gnus-kill-buffer gnus-article-buffer)
  4961.     (gnus-kill-buffer gnus-original-article-buffer)
  4962.     (setq gnus-article-current nil))
  4963.       (if (not gnus-kill-summary-on-exit)
  4964.       (gnus-deaden-summary)
  4965.     (gnus-close-group group)
  4966.     (gnus-summary-clear-local-variables)
  4967.     (set-buffer gnus-group-buffer)
  4968.     (gnus-summary-clear-local-variables)
  4969.     (when (get-buffer gnus-summary-buffer)
  4970.       (kill-buffer gnus-summary-buffer)))
  4971.       (unless gnus-single-article-buffer
  4972.     (setq gnus-article-current nil))
  4973.       (when gnus-use-trees
  4974.     (gnus-tree-close group))
  4975.       (gnus-async-prefetch-remove-group group)
  4976.       (when (get-buffer gnus-article-buffer)
  4977.     (bury-buffer gnus-article-buffer))
  4978.       ;; Return to the group buffer.
  4979.       (gnus-configure-windows 'group 'force)
  4980.       ;; Clear the current group name.
  4981.       (setq gnus-newsgroup-name nil)
  4982.       (when (equal (gnus-group-group-name) group)
  4983.     (gnus-group-next-unread-group 1))
  4984.       (when quit-config
  4985.         (gnus-handle-ephemeral-exit quit-config)))))
  4986.  
  4987. (defun gnus-handle-ephemeral-exit (quit-config)
  4988.   "Handle movement when leaving an ephemeral group.  The state
  4989. which existed when entering the ephemeral is reset."
  4990.   (if (not (buffer-name (car quit-config)))
  4991.       (gnus-configure-windows 'group 'force)
  4992.     (set-buffer (car quit-config))
  4993.     (cond ((eq major-mode 'gnus-summary-mode)
  4994.            (gnus-set-global-variables))
  4995.           ((eq major-mode 'gnus-article-mode)
  4996.            (save-excursion
  4997.              ;; The `gnus-summary-buffer' variable may point
  4998.              ;; to the old summary buffer when using a single
  4999.              ;; article buffer.
  5000.              (unless (gnus-buffer-live-p gnus-summary-buffer)
  5001.                (set-buffer gnus-group-buffer))
  5002.              (set-buffer gnus-summary-buffer)
  5003.              (gnus-set-global-variables))))
  5004.     (if (or (eq (cdr quit-config) 'article)
  5005.             (eq (cdr quit-config) 'pick))
  5006.         (progn
  5007.           ;; The current article may be from the ephemeral group
  5008.           ;; thus it is best that we reload this article
  5009.           (gnus-summary-show-article)
  5010.           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
  5011.               (gnus-configure-windows 'pick 'force)
  5012.             (gnus-configure-windows (cdr quit-config) 'force)))
  5013.       (gnus-configure-windows (cdr quit-config) 'force))
  5014.     (when (eq major-mode 'gnus-summary-mode)
  5015.       (gnus-summary-next-subject 1 nil t)
  5016.       (gnus-summary-recenter)
  5017.       (gnus-summary-position-point))))
  5018.  
  5019. ;;; Dead summaries.
  5020.  
  5021. (defvar gnus-dead-summary-mode-map nil)
  5022.  
  5023. (unless gnus-dead-summary-mode-map
  5024.   (setq gnus-dead-summary-mode-map (make-keymap))
  5025.   (suppress-keymap gnus-dead-summary-mode-map)
  5026.   (substitute-key-definition
  5027.    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
  5028.   (let ((keys '("\C-d" "\r" "\177" [delete])))
  5029.     (while keys
  5030.       (define-key gnus-dead-summary-mode-map
  5031.     (pop keys) 'gnus-summary-wake-up-the-dead))))
  5032.  
  5033. (defvar gnus-dead-summary-mode nil
  5034.   "Minor mode for Gnus summary buffers.")
  5035.  
  5036. (defun gnus-dead-summary-mode (&optional arg)
  5037.   "Minor mode for Gnus summary buffers."
  5038.   (interactive "P")
  5039.   (when (eq major-mode 'gnus-summary-mode)
  5040.     (make-local-variable 'gnus-dead-summary-mode)
  5041.     (setq gnus-dead-summary-mode
  5042.       (if (null arg) (not gnus-dead-summary-mode)
  5043.         (> (prefix-numeric-value arg) 0)))
  5044.     (when gnus-dead-summary-mode
  5045.       (gnus-add-minor-mode
  5046.        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
  5047.  
  5048. (defun gnus-deaden-summary ()
  5049.   "Make the current summary buffer into a dead summary buffer."
  5050.   ;; Kill any previous dead summary buffer.
  5051.   (when (and gnus-dead-summary
  5052.          (buffer-name gnus-dead-summary))
  5053.     (save-excursion
  5054.       (set-buffer gnus-dead-summary)
  5055.       (when gnus-dead-summary-mode
  5056.     (kill-buffer (current-buffer)))))
  5057.   ;; Make this the current dead summary.
  5058.   (setq gnus-dead-summary (current-buffer))
  5059.   (gnus-dead-summary-mode 1)
  5060.   (let ((name (buffer-name)))
  5061.     (when (string-match "Summary" name)
  5062.       (rename-buffer
  5063.        (concat (substring name 0 (match-beginning 0)) "Dead "
  5064.            (substring name (match-beginning 0)))
  5065.        t))))
  5066.  
  5067. (defun gnus-kill-or-deaden-summary (buffer)
  5068.   "Kill or deaden the summary BUFFER."
  5069.   (when (and (buffer-name buffer)
  5070.          (not gnus-single-article-buffer))
  5071.     (save-excursion
  5072.       (set-buffer buffer)
  5073.       (gnus-kill-buffer gnus-article-buffer)
  5074.       (gnus-kill-buffer gnus-original-article-buffer)))
  5075.   (cond (gnus-kill-summary-on-exit
  5076.      (when (and gnus-use-trees
  5077.             (and (get-buffer buffer)
  5078.              (buffer-name (get-buffer buffer))))
  5079.        (save-excursion
  5080.          (set-buffer (get-buffer buffer))
  5081.          (gnus-tree-close gnus-newsgroup-name)))
  5082.      (gnus-kill-buffer buffer))
  5083.     ((and (get-buffer buffer)
  5084.           (buffer-name (get-buffer buffer)))
  5085.      (save-excursion
  5086.        (set-buffer buffer)
  5087.        (gnus-deaden-summary)))))
  5088.  
  5089. (defun gnus-summary-wake-up-the-dead (&rest args)
  5090.   "Wake up the dead summary buffer."
  5091.   (interactive)
  5092.   (gnus-dead-summary-mode -1)
  5093.   (let ((name (buffer-name)))
  5094.     (when (string-match "Dead " name)
  5095.       (rename-buffer
  5096.        (concat (substring name 0 (match-beginning 0))
  5097.            (substring name (match-end 0)))
  5098.        t)))
  5099.   (gnus-message 3 "This dead summary is now alive again"))
  5100.  
  5101. ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
  5102. (defun gnus-summary-fetch-faq (&optional faq-dir)
  5103.   "Fetch the FAQ for the current group.
  5104. If FAQ-DIR (the prefix), prompt for a directory to search for the faq
  5105. in."
  5106.   (interactive
  5107.    (list
  5108.     (when current-prefix-arg
  5109.       (completing-read
  5110.        "Faq dir: " (and (listp gnus-group-faq-directory)
  5111.             (mapcar (lambda (file) (list file))
  5112.                 gnus-group-faq-directory))))))
  5113.   (let (gnus-faq-buffer)
  5114.     (when (setq gnus-faq-buffer
  5115.         (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
  5116.       (gnus-configure-windows 'summary-faq))))
  5117.  
  5118. ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
  5119. (defun gnus-summary-describe-group (&optional force)
  5120.   "Describe the current newsgroup."
  5121.   (interactive "P")
  5122.   (gnus-group-describe-group force gnus-newsgroup-name))
  5123.  
  5124. (defun gnus-summary-describe-briefly ()
  5125.   "Describe summary mode commands briefly."
  5126.   (interactive)
  5127.   (gnus-message 6
  5128.         (substitute-command-keys "\\<gnus-summary-mode-map>\\[gnus-summary-next-page]:Select  \\[gnus-summary-next-unread-article]:Forward  \\[gnus-summary-prev-unread-article]:Backward  \\[gnus-summary-exit]:Exit  \\[gnus-info-find-node]:Run Info     \\[gnus-summary-describe-briefly]:This help")))
  5129.  
  5130. ;; Walking around group mode buffer from summary mode.
  5131.  
  5132. (defun gnus-summary-next-group (&optional no-article target-group backward)
  5133.   "Exit current newsgroup and then select next unread newsgroup.
  5134. If prefix argument NO-ARTICLE is non-nil, no article is selected
  5135. initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
  5136. previous group instead."
  5137.   (interactive "P")
  5138.   (gnus-set-global-variables)
  5139.   ;; Stop pre-fetching.
  5140.   (gnus-async-halt-prefetch)
  5141.   (let ((current-group gnus-newsgroup-name)
  5142.     (current-buffer (current-buffer))
  5143.     entered)
  5144.     ;; First we semi-exit this group to update Xrefs and all variables.
  5145.     ;; We can't do a real exit, because the window conf must remain
  5146.     ;; the same in case the user is prompted for info, and we don't
  5147.     ;; want the window conf to change before that...
  5148.     (gnus-summary-exit t)
  5149.     (while (not entered)
  5150.       ;; Then we find what group we are supposed to enter.
  5151.       (set-buffer gnus-group-buffer)
  5152.       (gnus-group-jump-to-group current-group)
  5153.       (setq target-group
  5154.         (or target-group
  5155.         (if (eq gnus-keep-same-level 'best)
  5156.             (gnus-summary-best-group gnus-newsgroup-name)
  5157.           (gnus-summary-search-group backward gnus-keep-same-level))))
  5158.       (if (not target-group)
  5159.       ;; There are no further groups, so we return to the group
  5160.       ;; buffer.
  5161.       (progn
  5162.         (gnus-message 5 "Returning to the group buffer")
  5163.         (setq entered t)
  5164.         (when (gnus-buffer-live-p current-buffer)
  5165.           (set-buffer current-buffer)
  5166.           (gnus-summary-exit))
  5167.         (run-hooks 'gnus-group-no-more-groups-hook))
  5168.     ;; We try to enter the target group.
  5169.     (gnus-group-jump-to-group target-group)
  5170.     (let ((unreads (gnus-group-group-unread)))
  5171.       (if (and (or (eq t unreads)
  5172.                (and unreads (not (zerop unreads))))
  5173.            (gnus-summary-read-group
  5174.             target-group nil no-article
  5175.             (and (buffer-name current-buffer) current-buffer)))
  5176.           (setq entered t)
  5177.         (setq current-group target-group
  5178.           target-group nil)))))))
  5179.  
  5180. (defun gnus-summary-prev-group (&optional no-article)
  5181.   "Exit current newsgroup and then select previous unread newsgroup.
  5182. If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
  5183.   (interactive "P")
  5184.   (gnus-summary-next-group no-article nil t))
  5185.  
  5186. ;; Walking around summary lines.
  5187.  
  5188. (defun gnus-summary-first-subject (&optional unread)
  5189.   "Go to the first unread subject.
  5190. If UNREAD is non-nil, go to the first unread article.
  5191. Returns the article selected or nil if there are no unread articles."
  5192.   (interactive "P")
  5193.   (prog1
  5194.       (cond
  5195.        ;; Empty summary.
  5196.        ((null gnus-newsgroup-data)
  5197.     (gnus-message 3 "No articles in the group")
  5198.     nil)
  5199.        ;; Pick the first article.
  5200.        ((not unread)
  5201.     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
  5202.     (gnus-data-number (car gnus-newsgroup-data)))
  5203.        ;; No unread articles.
  5204.        ((null gnus-newsgroup-unreads)
  5205.     (gnus-message 3 "No more unread articles")
  5206.     nil)
  5207.        ;; Find the first unread article.
  5208.        (t
  5209.     (let ((data gnus-newsgroup-data))
  5210.       (while (and data
  5211.               (not (gnus-data-unread-p (car data))))
  5212.         (setq data (cdr data)))
  5213.       (when data
  5214.         (goto-char (gnus-data-pos (car data)))
  5215.         (gnus-data-number (car data))))))
  5216.     (gnus-summary-position-point)))
  5217.  
  5218. (defun gnus-summary-next-subject (n &optional unread dont-display)
  5219.   "Go to next N'th summary line.
  5220. If N is negative, go to the previous N'th subject line.
  5221. If UNREAD is non-nil, only unread articles are selected.
  5222. The difference between N and the actual number of steps taken is
  5223. returned."
  5224.   (interactive "p")
  5225.   (let ((backward (< n 0))
  5226.     (n (abs n)))
  5227.     (while (and (> n 0)
  5228.         (if backward
  5229.             (gnus-summary-find-prev unread)
  5230.           (gnus-summary-find-next unread)))
  5231.       (setq n (1- n)))
  5232.     (when (/= 0 n)
  5233.       (gnus-message 7 "No more%s articles"
  5234.             (if unread " unread" "")))
  5235.     (unless dont-display
  5236.       (gnus-summary-recenter)
  5237.       (gnus-summary-position-point))
  5238.     n))
  5239.  
  5240. (defun gnus-summary-next-unread-subject (n)
  5241.   "Go to next N'th unread summary line."
  5242.   (interactive "p")
  5243.   (gnus-summary-next-subject n t))
  5244.  
  5245. (defun gnus-summary-prev-subject (n &optional unread)
  5246.   "Go to previous N'th summary line.
  5247. If optional argument UNREAD is non-nil, only unread article is selected."
  5248.   (interactive "p")
  5249.   (gnus-summary-next-subject (- n) unread))
  5250.  
  5251. (defun gnus-summary-prev-unread-subject (n)
  5252.   "Go to previous N'th unread summary line."
  5253.   (interactive "p")
  5254.   (gnus-summary-next-subject (- n) t))
  5255.  
  5256. (defun gnus-summary-goto-subject (article &optional force silent)
  5257.   "Go the subject line of ARTICLE.
  5258. If FORCE, also allow jumping to articles not currently shown."
  5259.   (interactive "nArticle number: ")
  5260.   (let ((b (point))
  5261.     (data (gnus-data-find article)))
  5262.     ;; We read in the article if we have to.
  5263.     (and (not data)
  5264.      force
  5265.      (gnus-summary-insert-subject article (and (vectorp force) force) t)
  5266.      (setq data (gnus-data-find article)))
  5267.     (goto-char b)
  5268.     (if (not data)
  5269.     (progn
  5270.       (unless silent
  5271.         (gnus-message 3 "Can't find article %d" article))
  5272.       nil)
  5273.       (goto-char (gnus-data-pos data))
  5274.       article)))
  5275.  
  5276. ;; Walking around summary lines with displaying articles.
  5277.  
  5278. (defun gnus-summary-expand-window (&optional arg)
  5279.   "Make the summary buffer take up the entire Emacs frame.
  5280. Given a prefix, will force an `article' buffer configuration."
  5281.   (interactive "P")
  5282.   (gnus-set-global-variables)
  5283.   (if arg
  5284.       (gnus-configure-windows 'article 'force)
  5285.     (gnus-configure-windows 'summary 'force)))
  5286.  
  5287. (defun gnus-summary-display-article (article &optional all-header)
  5288.   "Display ARTICLE in article buffer."
  5289.   (gnus-set-global-variables)
  5290.   (if (null article)
  5291.       nil
  5292.     (prog1
  5293.     (if gnus-summary-display-article-function
  5294.         (funcall gnus-summary-display-article-function article all-header)
  5295.       (gnus-article-prepare article all-header))
  5296.       (run-hooks 'gnus-select-article-hook)
  5297.       (when (and gnus-current-article
  5298.          (not (zerop gnus-current-article)))
  5299.     (gnus-summary-goto-subject gnus-current-article))
  5300.       (gnus-summary-recenter)
  5301.       (when (and gnus-use-trees gnus-show-threads)
  5302.     (gnus-possibly-generate-tree article)
  5303.     (gnus-highlight-selected-tree article))
  5304.       ;; Successfully display article.
  5305.       (gnus-article-set-window-start
  5306.        (cdr (assq article gnus-newsgroup-bookmarks))))))
  5307.  
  5308. (defun gnus-summary-select-article (&optional all-headers force pseudo article)
  5309.   "Select the current article.
  5310. If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
  5311. non-nil, the article will be re-fetched even if it already present in
  5312. the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
  5313. be displayed."
  5314.   ;; Make sure we are in the summary buffer to work around bbdb bug.
  5315.   (unless (eq major-mode 'gnus-summary-mode)
  5316.     (set-buffer gnus-summary-buffer))
  5317.   (let ((article (or article (gnus-summary-article-number)))
  5318.     (all-headers (not (not all-headers))) ;Must be T or NIL.
  5319.     gnus-summary-display-article-function
  5320.     did)
  5321.     (and (not pseudo)
  5322.      (gnus-summary-article-pseudo-p article)
  5323.      (error "This is a pseudo-article"))
  5324.     (prog1
  5325.     (save-excursion
  5326.       (set-buffer gnus-summary-buffer)
  5327.       (if (or (and gnus-single-article-buffer
  5328.                (or (null gnus-current-article)
  5329.                (null gnus-article-current)
  5330.                (null (get-buffer gnus-article-buffer))
  5331.                (not (eq article (cdr gnus-article-current)))
  5332.                (not (equal (car gnus-article-current)
  5333.                        gnus-newsgroup-name))))
  5334.           (and (not gnus-single-article-buffer)
  5335.                (or (null gnus-current-article)
  5336.                (not (eq gnus-current-article article))))
  5337.           force)
  5338.           ;; The requested article is different from the current article.
  5339.           (prog1
  5340.           (gnus-summary-display-article article all-headers)
  5341.         (setq did article))
  5342.         (when (or all-headers gnus-show-all-headers)
  5343.           (gnus-article-show-all-headers))
  5344.         'old))
  5345.       (when did
  5346.     (gnus-article-set-window-start
  5347.      (cdr (assq article gnus-newsgroup-bookmarks)))))))
  5348.  
  5349. (defun gnus-summary-set-current-mark (&optional current-mark)
  5350.   "Obsolete function."
  5351.   nil)
  5352.  
  5353. (defun gnus-summary-next-article (&optional unread subject backward push)
  5354.   "Select the next article.
  5355. If UNREAD, only unread articles are selected.
  5356. If SUBJECT, only articles with SUBJECT are selected.
  5357. If BACKWARD, the previous article is selected instead of the next."
  5358.   (interactive "P")
  5359.   (gnus-set-global-variables)
  5360.   (cond
  5361.    ;; Is there such an article?
  5362.    ((and (gnus-summary-search-forward unread subject backward)
  5363.      (or (gnus-summary-display-article (gnus-summary-article-number))
  5364.          (eq (gnus-summary-article-mark) gnus-canceled-mark)))
  5365.     (gnus-summary-position-point))
  5366.    ;; If not, we try the first unread, if that is wanted.
  5367.    ((and subject
  5368.      gnus-auto-select-same
  5369.      (gnus-summary-first-unread-article))
  5370.     (gnus-summary-position-point)
  5371.     (gnus-message 6 "Wrapped"))
  5372.    ;; Try to get next/previous article not displayed in this group.
  5373.    ((and gnus-auto-extend-newsgroup
  5374.      (not unread) (not subject))
  5375.     (gnus-summary-goto-article
  5376.      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
  5377.      nil t))
  5378.    ;; Go to next/previous group.
  5379.    (t
  5380.     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
  5381.       (gnus-summary-jump-to-group gnus-newsgroup-name))
  5382.     (let ((cmd last-command-char)
  5383.       (point
  5384.        (save-excursion
  5385.          (set-buffer gnus-group-buffer)
  5386.          (point)))
  5387.       (group
  5388.        (if (eq gnus-keep-same-level 'best)
  5389.            (gnus-summary-best-group gnus-newsgroup-name)
  5390.          (gnus-summary-search-group backward gnus-keep-same-level))))
  5391.       ;; For some reason, the group window gets selected.  We change
  5392.       ;; it back.
  5393.       (select-window (get-buffer-window (current-buffer)))
  5394.       ;; Select next unread newsgroup automagically.
  5395.       (cond
  5396.        ((or (not gnus-auto-select-next)
  5397.         (not cmd))
  5398.     (gnus-message 7 "No more%s articles" (if unread " unread" "")))
  5399.        ((or (eq gnus-auto-select-next 'quietly)
  5400.         (and (eq gnus-auto-select-next 'slightly-quietly)
  5401.          push)
  5402.         (and (eq gnus-auto-select-next 'almost-quietly)
  5403.          (gnus-summary-last-article-p)))
  5404.     ;; Select quietly.
  5405.     (if (gnus-ephemeral-group-p gnus-newsgroup-name)
  5406.         (gnus-summary-exit)
  5407.       (gnus-message 7 "No more%s articles (%s)..."
  5408.             (if unread " unread" "")
  5409.             (if group (concat "selecting " group)
  5410.               "exiting"))
  5411.       (gnus-summary-next-group nil group backward)))
  5412.        (t
  5413.     (when (gnus-key-press-event-p last-input-event)
  5414.       (gnus-summary-walk-group-buffer
  5415.        gnus-newsgroup-name cmd unread backward point))))))))
  5416.  
  5417. (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
  5418.   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
  5419.               (?\C-p (gnus-group-prev-unread-group 1))))
  5420.     (cursor-in-echo-area t)
  5421.     keve key group ended)
  5422.     (save-excursion
  5423.       (set-buffer gnus-group-buffer)
  5424.       (goto-char start)
  5425.       (setq group
  5426.         (if (eq gnus-keep-same-level 'best)
  5427.         (gnus-summary-best-group gnus-newsgroup-name)
  5428.           (gnus-summary-search-group backward gnus-keep-same-level))))
  5429.     (while (not ended)
  5430.       (gnus-message
  5431.        5 "No more%s articles%s" (if unread " unread" "")
  5432.        (if (and group
  5433.         (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
  5434.        (format " (Type %s for %s [%s])"
  5435.            (single-key-description cmd) group
  5436.            (car (gnus-gethash group gnus-newsrc-hashtb)))
  5437.      (format " (Type %s to exit %s)"
  5438.          (single-key-description cmd)
  5439.          gnus-newsgroup-name)))
  5440.       ;; Confirm auto selection.
  5441.       (setq key (car (setq keve (gnus-read-event-char))))
  5442.       (setq ended t)
  5443.       (cond
  5444.        ((assq key keystrokes)
  5445.     (let ((obuf (current-buffer)))
  5446.       (switch-to-buffer gnus-group-buffer)
  5447.       (when group
  5448.         (gnus-group-jump-to-group group))
  5449.       (eval (cadr (assq key keystrokes)))
  5450.       (setq group (gnus-group-group-name))
  5451.       (switch-to-buffer obuf))
  5452.     (setq ended nil))
  5453.        ((equal key cmd)
  5454.     (if (or (not group)
  5455.         (gnus-ephemeral-group-p gnus-newsgroup-name))
  5456.         (gnus-summary-exit)
  5457.       (gnus-summary-next-group nil group backward)))
  5458.        (t
  5459.     (push (cdr keve) unread-command-events))))))
  5460.  
  5461. (defun gnus-summary-next-unread-article ()
  5462.   "Select unread article after current one."
  5463.   (interactive)
  5464.   (gnus-summary-next-article
  5465.    (or (not (eq gnus-summary-goto-unread 'never))
  5466.        (gnus-summary-last-article-p (gnus-summary-article-number)))
  5467.    (and gnus-auto-select-same
  5468.     (gnus-summary-article-subject))))
  5469.  
  5470. (defun gnus-summary-prev-article (&optional unread subject)
  5471.   "Select the article after the current one.
  5472. If UNREAD is non-nil, only unread articles are selected."
  5473.   (interactive "P")
  5474.   (gnus-summary-next-article unread subject t))
  5475.  
  5476. (defun gnus-summary-prev-unread-article ()
  5477.   "Select unread article before current one."
  5478.   (interactive)
  5479.   (gnus-summary-prev-article
  5480.    (or (not (eq gnus-summary-goto-unread 'never))
  5481.        (gnus-summary-first-article-p (gnus-summary-article-number)))
  5482.    (and gnus-auto-select-same
  5483.     (gnus-summary-article-subject))))
  5484.  
  5485. (defun gnus-summary-next-page (&optional lines circular)
  5486.   "Show next page of the selected article.
  5487. If at the end of the current article, select the next article.
  5488. LINES says how many lines should be scrolled up.
  5489.  
  5490. If CIRCULAR is non-nil, go to the start of the article instead of
  5491. selecting the next article when reaching the end of the current
  5492. article."
  5493.   (interactive "P")
  5494.   (setq gnus-summary-buffer (current-buffer))
  5495.   (gnus-set-global-variables)
  5496.   (let ((article (gnus-summary-article-number))
  5497.     (article-window (get-buffer-window gnus-article-buffer t))
  5498.     endp)
  5499.     (gnus-configure-windows 'article)
  5500.     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
  5501.     (if (and (eq gnus-summary-goto-unread 'never)
  5502.          (not (gnus-summary-last-article-p article)))
  5503.         (gnus-summary-next-article)
  5504.       (gnus-summary-next-unread-article))
  5505.       (if (or (null gnus-current-article)
  5506.           (null gnus-article-current)
  5507.           (/= article (cdr gnus-article-current))
  5508.           (not (equal (car gnus-article-current) gnus-newsgroup-name)))
  5509.       ;; Selected subject is different from current article's.
  5510.       (gnus-summary-display-article article)
  5511.     (when article-window
  5512.       (gnus-eval-in-buffer-window gnus-article-buffer
  5513.         (setq endp (gnus-article-next-page lines)))
  5514.       (when endp
  5515.         (cond (circular
  5516.            (gnus-summary-beginning-of-article))
  5517.           (lines
  5518.            (gnus-message 3 "End of message"))
  5519.           ((null lines)
  5520.            (if (and (eq gnus-summary-goto-unread 'never)
  5521.                 (not (gnus-summary-last-article-p article)))
  5522.                (gnus-summary-next-article)
  5523.              (gnus-summary-next-unread-article))))))))
  5524.     (gnus-summary-recenter)
  5525.     (gnus-summary-position-point)))
  5526.  
  5527. (defun gnus-summary-prev-page (&optional lines move)
  5528.   "Show previous page of selected article.
  5529. Argument LINES specifies lines to be scrolled down.
  5530. If MOVE, move to the previous unread article if point is at
  5531. the beginning of the buffer."
  5532.   (interactive "P")
  5533.   (gnus-set-global-variables)
  5534.   (let ((article (gnus-summary-article-number))
  5535.     (article-window (get-buffer-window gnus-article-buffer t))
  5536.     endp)
  5537.     (gnus-configure-windows 'article)
  5538.     (if (or (null gnus-current-article)
  5539.         (null gnus-article-current)
  5540.         (/= article (cdr gnus-article-current))
  5541.         (not (equal (car gnus-article-current) gnus-newsgroup-name)))
  5542.     ;; Selected subject is different from current article's.
  5543.     (gnus-summary-display-article article)
  5544.       (gnus-summary-recenter)
  5545.       (when article-window
  5546.     (gnus-eval-in-buffer-window gnus-article-buffer
  5547.       (setq endp (gnus-article-prev-page lines)))
  5548.     (when (and move endp)
  5549.       (cond (lines
  5550.          (gnus-message 3 "Beginning of message"))
  5551.         ((null lines)
  5552.          (if (and (eq gnus-summary-goto-unread 'never)
  5553.               (not (gnus-summary-first-article-p article)))
  5554.              (gnus-summary-prev-article)
  5555.            (gnus-summary-prev-unread-article))))))))
  5556.   (gnus-summary-position-point))
  5557.  
  5558. (defun gnus-summary-prev-page-or-article (&optional lines)
  5559.   "Show previous page of selected article.
  5560. Argument LINES specifies lines to be scrolled down.
  5561. If at the beginning of the article, go to the next article."
  5562.   (interactive "P")
  5563.   (gnus-summary-prev-page lines t))
  5564.  
  5565. (defun gnus-summary-scroll-up (lines)
  5566.   "Scroll up (or down) one line current article.
  5567. Argument LINES specifies lines to be scrolled up (or down if negative)."
  5568.   (interactive "p")
  5569.   (gnus-set-global-variables)
  5570.   (gnus-configure-windows 'article)
  5571.   (gnus-summary-show-thread)
  5572.   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
  5573.     (gnus-eval-in-buffer-window gnus-article-buffer
  5574.       (cond ((> lines 0)
  5575.          (when (gnus-article-next-page lines)
  5576.            (gnus-message 3 "End of message")))
  5577.         ((< lines 0)
  5578.          (gnus-article-prev-page (- lines))))))
  5579.   (gnus-summary-recenter)
  5580.   (gnus-summary-position-point))
  5581.  
  5582. (defun gnus-summary-next-same-subject ()
  5583.   "Select next article which has the same subject as current one."
  5584.   (interactive)
  5585.   (gnus-set-global-variables)
  5586.   (gnus-summary-next-article nil (gnus-summary-article-subject)))
  5587.  
  5588. (defun gnus-summary-prev-same-subject ()
  5589.   "Select previous article which has the same subject as current one."
  5590.   (interactive)
  5591.   (gnus-set-global-variables)
  5592.   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
  5593.  
  5594. (defun gnus-summary-next-unread-same-subject ()
  5595.   "Select next unread article which has the same subject as current one."
  5596.   (interactive)
  5597.   (gnus-set-global-variables)
  5598.   (gnus-summary-next-article t (gnus-summary-article-subject)))
  5599.  
  5600. (defun gnus-summary-prev-unread-same-subject ()
  5601.   "Select previous unread article which has the same subject as current one."
  5602.   (interactive)
  5603.   (gnus-set-global-variables)
  5604.   (gnus-summary-prev-article t (gnus-summary-article-subject)))
  5605.  
  5606. (defun gnus-summary-first-unread-article ()
  5607.   "Select the first unread article.
  5608. Return nil if there are no unread articles."
  5609.   (interactive)
  5610.   (gnus-set-global-variables)
  5611.   (prog1
  5612.       (when (gnus-summary-first-subject t)
  5613.     (gnus-summary-show-thread)
  5614.     (gnus-summary-first-subject t)
  5615.     (gnus-summary-display-article (gnus-summary-article-number)))
  5616.     (gnus-summary-position-point)))
  5617.  
  5618. (defun gnus-summary-first-article ()
  5619.   "Select the first article.
  5620. Return nil if there are no articles."
  5621.   (interactive)
  5622.   (gnus-set-global-variables)
  5623.   (prog1
  5624.       (when (gnus-summary-first-subject)
  5625.       (gnus-summary-show-thread)
  5626.       (gnus-summary-first-subject)
  5627.       (gnus-summary-display-article (gnus-summary-article-number)))
  5628.     (gnus-summary-position-point)))
  5629.  
  5630. (defun gnus-summary-best-unread-article ()
  5631.   "Select the unread article with the highest score."
  5632.   (interactive)
  5633.   (gnus-set-global-variables)
  5634.   (let ((best -1000000)
  5635.     (data gnus-newsgroup-data)
  5636.     article score)
  5637.     (while data
  5638.       (and (gnus-data-unread-p (car data))
  5639.        (> (setq score
  5640.             (gnus-summary-article-score (gnus-data-number (car data))))
  5641.           best)
  5642.        (setq best score
  5643.          article (gnus-data-number (car data))))
  5644.       (setq data (cdr data)))
  5645.     (prog1
  5646.     (if article
  5647.         (gnus-summary-goto-article article)
  5648.       (error "No unread articles"))
  5649.       (gnus-summary-position-point))))
  5650.  
  5651. (defun gnus-summary-last-subject ()
  5652.   "Go to the last displayed subject line in the group."
  5653.   (let ((article (gnus-data-number (car (gnus-data-list t)))))
  5654.     (when article
  5655.       (gnus-summary-goto-subject article))))
  5656.  
  5657. (defun gnus-summary-goto-article (article &optional all-headers force)
  5658.   "Fetch ARTICLE and display it if it exists.
  5659. If ALL-HEADERS is non-nil, no header lines are hidden."
  5660.   (interactive
  5661.    (list
  5662.     (string-to-int
  5663.      (completing-read
  5664.       "Article number: "
  5665.       (mapcar (lambda (number) (list (int-to-string number)))
  5666.           gnus-newsgroup-limit)))
  5667.     current-prefix-arg
  5668.     t))
  5669.   (prog1
  5670.       (if (gnus-summary-goto-subject article force)
  5671.       (gnus-summary-display-article article all-headers)
  5672.     (gnus-message 4 "Couldn't go to article %s" article) nil)
  5673.     (gnus-summary-position-point)))
  5674.  
  5675. (defun gnus-summary-goto-last-article ()
  5676.   "Go to the previously read article."
  5677.   (interactive)
  5678.   (prog1
  5679.       (when gnus-last-article
  5680.     (gnus-summary-goto-article gnus-last-article))
  5681.     (gnus-summary-position-point)))
  5682.  
  5683. (defun gnus-summary-pop-article (number)
  5684.   "Pop one article off the history and go to the previous.
  5685. NUMBER articles will be popped off."
  5686.   (interactive "p")
  5687.   (let (to)
  5688.     (setq gnus-newsgroup-history
  5689.       (cdr (setq to (nthcdr number gnus-newsgroup-history))))
  5690.     (if to
  5691.     (gnus-summary-goto-article (car to))
  5692.       (error "Article history empty")))
  5693.   (gnus-summary-position-point))
  5694.  
  5695. ;; Summary commands and functions for limiting the summary buffer.
  5696.  
  5697. (defun gnus-summary-limit-to-articles (n)
  5698.   "Limit the summary buffer to the next N articles.
  5699. If not given a prefix, use the process marked articles instead."
  5700.   (interactive "P")
  5701.   (gnus-set-global-variables)
  5702.   (prog1
  5703.       (let ((articles (gnus-summary-work-articles n)))
  5704.     (setq gnus-newsgroup-processable nil)
  5705.     (gnus-summary-limit articles))
  5706.     (gnus-summary-position-point)))
  5707.  
  5708. (defun gnus-summary-pop-limit (&optional total)
  5709.   "Restore the previous limit.
  5710. If given a prefix, remove all limits."
  5711.   (interactive "P")
  5712.   (gnus-set-global-variables)
  5713.   (when total
  5714.     (setq gnus-newsgroup-limits
  5715.       (list (mapcar (lambda (h) (mail-header-number h))
  5716.             gnus-newsgroup-headers))))
  5717.   (unless gnus-newsgroup-limits
  5718.     (error "No limit to pop"))
  5719.   (prog1
  5720.       (gnus-summary-limit nil 'pop)
  5721.     (gnus-summary-position-point)))
  5722.  
  5723. (defun gnus-summary-limit-to-subject (subject &optional header)
  5724.   "Limit the summary buffer to articles that have subjects that match a regexp."
  5725.   (interactive "sLimit to subject (regexp): ")
  5726.   (unless header
  5727.     (setq header "subject"))
  5728.   (when (not (equal "" subject))
  5729.     (prog1
  5730.     (let ((articles (gnus-summary-find-matching
  5731.              (or header "subject") subject 'all)))
  5732.       (unless articles
  5733.         (error "Found no matches for \"%s\"" subject))
  5734.       (gnus-summary-limit articles))
  5735.       (gnus-summary-position-point))))
  5736.  
  5737. (defun gnus-summary-limit-to-author (from)
  5738.   "Limit the summary buffer to articles that have authors that match a regexp."
  5739.   (interactive "sLimit to author (regexp): ")
  5740.   (gnus-summary-limit-to-subject from "from"))
  5741.  
  5742. (defun gnus-summary-limit-to-age (age &optional younger-p)
  5743.   "Limit the summary buffer to articles that are older than (or equal) AGE days.
  5744. If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
  5745. articles that are younger than AGE days."
  5746.   (interactive "nTime in days: \nP")
  5747.   (prog1
  5748.       (let ((data gnus-newsgroup-data)
  5749.         (cutoff (nnmail-days-to-time age))
  5750.         articles d date is-younger)
  5751.     (while (setq d (pop data))
  5752.       (when (and (vectorp (gnus-data-header d))
  5753.              (setq date (mail-header-date (gnus-data-header d))))
  5754.         (setq is-younger (nnmail-time-less
  5755.                   (nnmail-time-since (nnmail-date-to-time date))
  5756.                   cutoff))
  5757.         (when (if younger-p is-younger (not is-younger))
  5758.           (push (gnus-data-number d) articles))))
  5759.     (gnus-summary-limit (nreverse articles)))
  5760.     (gnus-summary-position-point)))
  5761.  
  5762. (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
  5763. (make-obsolete
  5764.  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
  5765.  
  5766. (defun gnus-summary-limit-to-unread (&optional all)
  5767.   "Limit the summary buffer to articles that are not marked as read.
  5768. If ALL is non-nil, limit strictly to unread articles."
  5769.   (interactive "P")
  5770.   (if all
  5771.       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
  5772.     (gnus-summary-limit-to-marks
  5773.      ;; Concat all the marks that say that an article is read and have
  5774.      ;; those removed.
  5775.      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
  5776.        gnus-killed-mark gnus-kill-file-mark
  5777.        gnus-low-score-mark gnus-expirable-mark
  5778.        gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
  5779.        gnus-duplicate-mark gnus-souped-mark)
  5780.      'reverse)))
  5781.  
  5782. (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
  5783. (make-obsolete 'gnus-summary-delete-marked-with
  5784.            'gnus-summary-limit-exlude-marks)
  5785.  
  5786. (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
  5787.   "Exclude articles that are marked with MARKS (e.g. \"DK\").
  5788. If REVERSE, limit the summary buffer to articles that are marked
  5789. with MARKS.  MARKS can either be a string of marks or a list of marks.
  5790. Returns how many articles were removed."
  5791.   (interactive "sMarks: ")
  5792.   (gnus-summary-limit-to-marks marks t))
  5793.  
  5794. (defun gnus-summary-limit-to-marks (marks &optional reverse)
  5795.   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
  5796. If REVERSE (the prefix), limit the summary buffer to articles that are
  5797. not marked with MARKS.  MARKS can either be a string of marks or a
  5798. list of marks.
  5799. Returns how many articles were removed."
  5800.   (interactive (list (read-string "Marks: ") current-prefix-arg))
  5801.   (gnus-set-global-variables)
  5802.   (prog1
  5803.       (let ((data gnus-newsgroup-data)
  5804.         (marks (if (listp marks) marks
  5805.              (append marks nil))) ; Transform to list.
  5806.         articles)
  5807.     (while data
  5808.       (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
  5809.           (memq (gnus-data-mark (car data)) marks))
  5810.         (push (gnus-data-number (car data)) articles))
  5811.       (setq data (cdr data)))
  5812.     (gnus-summary-limit articles))
  5813.     (gnus-summary-position-point)))
  5814.  
  5815. (defun gnus-summary-limit-to-score (&optional score)
  5816.   "Limit to articles with score at or above SCORE."
  5817.   (interactive "P")
  5818.   (gnus-set-global-variables)
  5819.   (setq score (if score
  5820.           (prefix-numeric-value score)
  5821.         (or gnus-summary-default-score 0)))
  5822.   (let ((data gnus-newsgroup-data)
  5823.     articles)
  5824.     (while data
  5825.       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
  5826.         score)
  5827.     (push (gnus-data-number (car data)) articles))
  5828.       (setq data (cdr data)))
  5829.     (prog1
  5830.     (gnus-summary-limit articles)
  5831.       (gnus-summary-position-point))))
  5832.  
  5833. (defun gnus-summary-limit-include-dormant ()
  5834.   "Display all the hidden articles that are marked as dormant."
  5835.   (interactive)
  5836.   (gnus-set-global-variables)
  5837.   (unless gnus-newsgroup-dormant
  5838.     (error "There are no dormant articles in this group"))
  5839.   (prog1
  5840.       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
  5841.     (gnus-summary-position-point)))
  5842.  
  5843. (defun gnus-summary-limit-exclude-dormant ()
  5844.   "Hide all dormant articles."
  5845.   (interactive)
  5846.   (gnus-set-global-variables)
  5847.   (prog1
  5848.       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
  5849.     (gnus-summary-position-point)))
  5850.  
  5851. (defun gnus-summary-limit-exclude-childless-dormant ()
  5852.   "Hide all dormant articles that have no children."
  5853.   (interactive)
  5854.   (gnus-set-global-variables)
  5855.   (let ((data (gnus-data-list t))
  5856.     articles d children)
  5857.     ;; Find all articles that are either not dormant or have
  5858.     ;; children.
  5859.     (while (setq d (pop data))
  5860.       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
  5861.         (and (setq children
  5862.                (gnus-article-children (gnus-data-number d)))
  5863.              (let (found)
  5864.                (while children
  5865.              (when (memq (car children) articles)
  5866.                (setq children nil
  5867.                  found t))
  5868.              (pop children))
  5869.                found)))
  5870.     (push (gnus-data-number d) articles)))
  5871.     ;; Do the limiting.
  5872.     (prog1
  5873.     (gnus-summary-limit articles)
  5874.       (gnus-summary-position-point))))
  5875.  
  5876. (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
  5877.   "Mark all unread excluded articles as read.
  5878. If ALL, mark even excluded ticked and dormants as read."
  5879.   (interactive "P")
  5880.   (let ((articles (gnus-sorted-complement
  5881.            (sort
  5882.             (mapcar (lambda (h) (mail-header-number h))
  5883.                 gnus-newsgroup-headers)
  5884.             '<)
  5885.            (sort gnus-newsgroup-limit '<)))
  5886.     article)
  5887.     (setq gnus-newsgroup-unreads gnus-newsgroup-limit)
  5888.     (if all
  5889.     (setq gnus-newsgroup-dormant nil
  5890.           gnus-newsgroup-marked nil
  5891.           gnus-newsgroup-reads
  5892.           (nconc
  5893.            (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
  5894.            gnus-newsgroup-reads))
  5895.       (while (setq article (pop articles))
  5896.     (unless (or (memq article gnus-newsgroup-dormant)
  5897.             (memq article gnus-newsgroup-marked))
  5898.       (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
  5899.  
  5900. (defun gnus-summary-limit (articles &optional pop)
  5901.   (if pop
  5902.       ;; We pop the previous limit off the stack and use that.
  5903.       (setq articles (car gnus-newsgroup-limits)
  5904.         gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
  5905.     ;; We use the new limit, so we push the old limit on the stack.
  5906.     (push gnus-newsgroup-limit gnus-newsgroup-limits))
  5907.   ;; Set the limit.
  5908.   (setq gnus-newsgroup-limit articles)
  5909.   (let ((total (length gnus-newsgroup-data))
  5910.     (data (gnus-data-find-list (gnus-summary-article-number)))
  5911.     (gnus-summary-mark-below nil)    ; Inhibit this.
  5912.     found)
  5913.     ;; This will do all the work of generating the new summary buffer
  5914.     ;; according to the new limit.
  5915.     (gnus-summary-prepare)
  5916.     ;; Hide any threads, possibly.
  5917.     (and gnus-show-threads
  5918.      gnus-thread-hide-subtree
  5919.      (gnus-summary-hide-all-threads))
  5920.     ;; Try to return to the article you were at, or one in the
  5921.     ;; neighborhood.
  5922.     (when data
  5923.       ;; We try to find some article after the current one.
  5924.       (while data
  5925.     (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
  5926.       (setq data nil
  5927.         found t))
  5928.     (setq data (cdr data))))
  5929.     (unless found
  5930.       ;; If there is no data, that means that we were after the last
  5931.       ;; article.  The same goes when we can't find any articles
  5932.       ;; after the current one.
  5933.       (goto-char (point-max))
  5934.       (gnus-summary-find-prev))
  5935.     ;; We return how many articles were removed from the summary
  5936.     ;; buffer as a result of the new limit.
  5937.     (- total (length gnus-newsgroup-data))))
  5938.  
  5939. (defsubst gnus-invisible-cut-children (threads)
  5940.   (let ((num 0))
  5941.     (while threads
  5942.       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
  5943.     (incf num))
  5944.       (pop threads))
  5945.     (< num 2)))
  5946.  
  5947. (defsubst gnus-cut-thread (thread)
  5948.   "Go forwards in the thread until we find an article that we want to display."
  5949.   (when (or (eq gnus-fetch-old-headers 'some)
  5950.         (eq gnus-build-sparse-threads 'some)
  5951.         (eq gnus-build-sparse-threads 'more))
  5952.     ;; Deal with old-fetched headers and sparse threads.
  5953.     (while (and
  5954.         thread
  5955.         (or
  5956.          (gnus-summary-article-sparse-p (mail-header-number (car thread)))
  5957.          (gnus-summary-article-ancient-p
  5958.           (mail-header-number (car thread))))
  5959.         (progn
  5960.           (if (<= (length (cdr thread)) 1)
  5961.           (setq gnus-newsgroup-limit
  5962.             (delq (mail-header-number (car thread))
  5963.                   gnus-newsgroup-limit)
  5964.             thread (cadr thread))
  5965.         (when (gnus-invisible-cut-children (cdr thread))
  5966.           (let ((th (cdr thread)))
  5967.             (while th
  5968.               (if (memq (mail-header-number (caar th))
  5969.                 gnus-newsgroup-limit)
  5970.               (setq thread (car th)
  5971.                 th nil)
  5972.             (setq th (cdr th)))))))))))
  5973.   thread)
  5974.  
  5975. (defun gnus-cut-threads (threads)
  5976.   "Cut off all uninteresting articles from the beginning of threads."
  5977.   (when (or (eq gnus-fetch-old-headers 'some)
  5978.         (eq gnus-build-sparse-threads 'some)
  5979.         (eq gnus-build-sparse-threads 'more))
  5980.     (let ((th threads))
  5981.       (while th
  5982.     (setcar th (gnus-cut-thread (car th)))
  5983.     (setq th (cdr th)))))
  5984.   ;; Remove nixed out threads.
  5985.   (delq nil threads))
  5986.  
  5987. (defun gnus-summary-initial-limit (&optional show-if-empty)
  5988.   "Figure out what the initial limit is supposed to be on group entry.
  5989. This entails weeding out unwanted dormants, low-scored articles,
  5990. fetch-old-headers verbiage, and so on."
  5991.   ;; Most groups have nothing to remove.
  5992.   (if (or gnus-inhibit-limiting
  5993.       (and (null gnus-newsgroup-dormant)
  5994.            (not (eq gnus-fetch-old-headers 'some))
  5995.            (null gnus-summary-expunge-below)
  5996.            (not (eq gnus-build-sparse-threads 'some))
  5997.            (not (eq gnus-build-sparse-threads 'more))
  5998.            (null gnus-thread-expunge-below)
  5999.            (not gnus-use-nocem)))
  6000.       ()                ; Do nothing.
  6001.     (push gnus-newsgroup-limit gnus-newsgroup-limits)
  6002.     (setq gnus-newsgroup-limit nil)
  6003.     (mapatoms
  6004.      (lambda (node)
  6005.        (unless (car (symbol-value node))
  6006.      ;; These threads have no parents -- they are roots.
  6007.      (let ((nodes (cdr (symbol-value node)))
  6008.            thread)
  6009.        (while nodes
  6010.          (if (and gnus-thread-expunge-below
  6011.               (< (gnus-thread-total-score (car nodes))
  6012.              gnus-thread-expunge-below))
  6013.          (gnus-expunge-thread (pop nodes))
  6014.            (setq thread (pop nodes))
  6015.            (gnus-summary-limit-children thread))))))
  6016.      gnus-newsgroup-dependencies)
  6017.     ;; If this limitation resulted in an empty group, we might
  6018.     ;; pop the previous limit and use it instead.
  6019.     (when (and (not gnus-newsgroup-limit)
  6020.            show-if-empty)
  6021.       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
  6022.     gnus-newsgroup-limit))
  6023.  
  6024. (defun gnus-summary-limit-children (thread)
  6025.   "Return 1 if this subthread is visible and 0 if it is not."
  6026.   ;; First we get the number of visible children to this thread.  This
  6027.   ;; is done by recursing down the thread using this function, so this
  6028.   ;; will really go down to a leaf article first, before slowly
  6029.   ;; working its way up towards the root.
  6030.   (when thread
  6031.     (let ((children
  6032.        (if (cdr thread)
  6033.            (apply '+ (mapcar 'gnus-summary-limit-children
  6034.                  (cdr thread)))
  6035.          0))
  6036.       (number (mail-header-number (car thread)))
  6037.       score)
  6038.       (if (and
  6039.        (not (memq number gnus-newsgroup-marked))
  6040.        (or
  6041.         ;; If this article is dormant and has absolutely no visible
  6042.         ;; children, then this article isn't visible.
  6043.         (and (memq number gnus-newsgroup-dormant)
  6044.          (zerop children))
  6045.         ;; If this is "fetch-old-headered" and there is no
  6046.         ;; visible children, then we don't want this article.
  6047.         (and (eq gnus-fetch-old-headers 'some)
  6048.          (gnus-summary-article-ancient-p number)
  6049.          (zerop children))
  6050.         ;; If this is a sparsely inserted article with no children,
  6051.         ;; we don't want it.
  6052.         (and (eq gnus-build-sparse-threads 'some)
  6053.          (gnus-summary-article-sparse-p number)
  6054.          (zerop children))
  6055.         ;; If we use expunging, and this article is really
  6056.         ;; low-scored, then we don't want this article.
  6057.         (when (and gnus-summary-expunge-below
  6058.                (< (setq score
  6059.                 (or (cdr (assq number gnus-newsgroup-scored))
  6060.                     gnus-summary-default-score))
  6061.               gnus-summary-expunge-below))
  6062.           ;; We increase the expunge-tally here, but that has
  6063.           ;; nothing to do with the limits, really.
  6064.           (incf gnus-newsgroup-expunged-tally)
  6065.           ;; We also mark as read here, if that's wanted.
  6066.           (when (and gnus-summary-mark-below
  6067.              (< score gnus-summary-mark-below))
  6068.         (setq gnus-newsgroup-unreads
  6069.               (delq number gnus-newsgroup-unreads))
  6070.         (if gnus-newsgroup-auto-expire
  6071.             (push number gnus-newsgroup-expirable)
  6072.           (push (cons number gnus-low-score-mark)
  6073.             gnus-newsgroup-reads)))
  6074.           t)
  6075.         ;; Check NoCeM things.
  6076.         (if (and gnus-use-nocem
  6077.              (gnus-nocem-unwanted-article-p
  6078.               (mail-header-id (car thread))))
  6079.         (progn
  6080.           (setq gnus-newsgroup-unreads
  6081.             (delq number gnus-newsgroup-unreads))
  6082.           t))))
  6083.       ;; Nope, invisible article.
  6084.       0
  6085.     ;; Ok, this article is to be visible, so we add it to the limit
  6086.     ;; and return 1.
  6087.     (push number gnus-newsgroup-limit)
  6088.     1))))
  6089.  
  6090. (defun gnus-expunge-thread (thread)
  6091.   "Mark all articles in THREAD as read."
  6092.   (let* ((number (mail-header-number (car thread))))
  6093.     (incf gnus-newsgroup-expunged-tally)
  6094.     ;; We also mark as read here, if that's wanted.
  6095.     (setq gnus-newsgroup-unreads
  6096.       (delq number gnus-newsgroup-unreads))
  6097.     (if gnus-newsgroup-auto-expire
  6098.     (push number gnus-newsgroup-expirable)
  6099.       (push (cons number gnus-low-score-mark)
  6100.         gnus-newsgroup-reads)))
  6101.   ;; Go recursively through all subthreads.
  6102.   (mapcar 'gnus-expunge-thread (cdr thread)))
  6103.  
  6104. ;; Summary article oriented commands
  6105.  
  6106. (defun gnus-summary-refer-parent-article (n)
  6107.   "Refer parent article N times.
  6108. If N is negative, go to ancestor -N instead.
  6109. The difference between N and the number of articles fetched is returned."
  6110.   (interactive "p")
  6111.   (gnus-set-global-variables)
  6112.   (let ((skip 1)
  6113.     error header ref)
  6114.     (when (not (natnump n))
  6115.       (setq skip (abs n)
  6116.         n 1))
  6117.     (while (and (> n 0)
  6118.         (not error))
  6119.       (setq header (gnus-summary-article-header))
  6120.       (if (and (eq (mail-header-number header)
  6121.            (cdr gnus-article-current))
  6122.            (equal gnus-newsgroup-name
  6123.               (car gnus-article-current)))
  6124.       ;; If we try to find the parent of the currently
  6125.       ;; displayed article, then we take a look at the actual
  6126.       ;; References header, since this is slightly more
  6127.       ;; reliable than the References field we got from the
  6128.       ;; server.
  6129.       (save-excursion
  6130.         (set-buffer gnus-original-article-buffer)
  6131.         (nnheader-narrow-to-headers)
  6132.         (unless (setq ref (message-fetch-field "references"))
  6133.           (setq ref (message-fetch-field "in-reply-to")))
  6134.         (widen))
  6135.     (setq ref
  6136.           ;; It's not the current article, so we take a bet on
  6137.           ;; the value we got from the server.
  6138.           (mail-header-references header)))
  6139.       (if (and ref
  6140.            (not (equal ref "")))
  6141.       (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
  6142.         (gnus-message 1 "Couldn't find parent"))
  6143.     (gnus-message 1 "No references in article %d"
  6144.               (gnus-summary-article-number))
  6145.     (setq error t))
  6146.       (decf n))
  6147.     (gnus-summary-position-point)
  6148.     n))
  6149.  
  6150. (defun gnus-summary-refer-references ()
  6151.   "Fetch all articles mentioned in the References header.
  6152. Return how many articles were fetched."
  6153.   (interactive)
  6154.   (gnus-set-global-variables)
  6155.   (let ((ref (mail-header-references (gnus-summary-article-header)))
  6156.     (current (gnus-summary-article-number))
  6157.     (n 0))
  6158.     (if (or (not ref)
  6159.         (equal ref ""))
  6160.     (error "No References in the current article")
  6161.       ;; For each Message-ID in the References header...
  6162.       (while (string-match "<[^>]*>" ref)
  6163.     (incf n)
  6164.     ;; ... fetch that article.
  6165.     (gnus-summary-refer-article
  6166.      (prog1 (match-string 0 ref)
  6167.        (setq ref (substring ref (match-end 0))))))
  6168.       (gnus-summary-goto-subject current)
  6169.       (gnus-summary-position-point)
  6170.       n)))
  6171.  
  6172. (defun gnus-summary-refer-article (message-id &optional arg)
  6173.   "Fetch an article specified by MESSAGE-ID.
  6174. If ARG (the prefix), fetch the article using `gnus-refer-article-method'
  6175. or `gnus-select-method', no matter what backend the article comes from."
  6176.   (interactive "sMessage-ID: \nP")
  6177.   (when (and (stringp message-id)
  6178.          (not (zerop (length message-id))))
  6179.     ;; Construct the correct Message-ID if necessary.
  6180.     ;; Suggested by tale@pawl.rpi.edu.
  6181.     (unless (string-match "^<" message-id)
  6182.       (setq message-id (concat "<" message-id)))
  6183.     (unless (string-match ">$" message-id)
  6184.       (setq message-id (concat message-id ">")))
  6185.     (let* ((header (gnus-id-to-header message-id))
  6186.        (sparse (and header
  6187.             (gnus-summary-article-sparse-p
  6188.              (mail-header-number header))
  6189.             (memq (mail-header-number header)
  6190.                   gnus-newsgroup-limit))))
  6191.       (if (and header
  6192.            (or (not (gnus-summary-article-sparse-p
  6193.              (mail-header-number header)))
  6194.            sparse))
  6195.       (prog1
  6196.               ;; The article is present in the buffer, so we just go to it.
  6197.           (gnus-summary-goto-article
  6198.                (mail-header-number header) nil t)
  6199.         (when sparse
  6200.           (gnus-summary-update-article (mail-header-number header))))
  6201.     ;; We fetch the article
  6202.     (let ((gnus-override-method
  6203.            (cond ((gnus-news-group-p gnus-newsgroup-name)
  6204.               gnus-refer-article-method)
  6205.              (arg
  6206.               (or gnus-refer-article-method gnus-select-method))
  6207.              (t nil)))
  6208.           number)
  6209.       ;; Start the special refer-article method, if necessary.
  6210.       (when (and gnus-refer-article-method
  6211.              (gnus-news-group-p gnus-newsgroup-name))
  6212.         (gnus-check-server gnus-refer-article-method))
  6213.       ;; Fetch the header, and display the article.
  6214.       (if (setq number (gnus-summary-insert-subject message-id))
  6215.           (gnus-summary-select-article nil nil nil number)
  6216.         (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
  6217.  
  6218. (defun gnus-summary-enter-digest-group (&optional force)
  6219.   "Enter an nndoc group based on the current article.
  6220. If FORCE, force a digest interpretation.  If not, try
  6221. to guess what the document format is."
  6222.   (interactive "P")
  6223.   (gnus-set-global-variables)
  6224.   (let ((conf gnus-current-window-configuration))
  6225.     (save-excursion
  6226.       (gnus-summary-select-article))
  6227.     (setq gnus-current-window-configuration conf)
  6228.     (let* ((name (format "%s-%d"
  6229.              (gnus-group-prefixed-name
  6230.               gnus-newsgroup-name (list 'nndoc ""))
  6231.              (save-excursion
  6232.                (set-buffer gnus-summary-buffer)
  6233.                gnus-current-article)))
  6234.        (ogroup gnus-newsgroup-name)
  6235.        (params (append (gnus-info-params (gnus-get-info ogroup))
  6236.                (list (cons 'to-group ogroup))
  6237.                (list (cons 'save-article-group ogroup))))
  6238.        (case-fold-search t)
  6239.        (buf (current-buffer))
  6240.        dig)
  6241.       (save-excursion
  6242.     (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
  6243.     (insert-buffer-substring gnus-original-article-buffer)
  6244.     ;; Remove lines that may lead nndoc to misinterpret the
  6245.     ;; document type.
  6246.     (narrow-to-region
  6247.      (goto-char (point-min))
  6248.      (or (search-forward "\n\n" nil t) (point)))
  6249.     (goto-char (point-min))
  6250.     (delete-matching-lines "^\\(Path\\):\\|^From ")
  6251.     (widen))
  6252.       (unwind-protect
  6253.           (if (gnus-group-read-ephemeral-group
  6254.                name `(nndoc ,name (nndoc-address ,(get-buffer dig))
  6255.                             (nndoc-article-type
  6256.                              ,(if force 'digest 'guess))) t)
  6257.               ;; Make all postings to this group go to the parent group.
  6258.               (nconc (gnus-info-params (gnus-get-info name))
  6259.                      params)
  6260.             ;; Couldn't select this doc group.
  6261.             (switch-to-buffer buf)
  6262.             (gnus-set-global-variables)
  6263.             (gnus-configure-windows 'summary)
  6264.             (gnus-message 3 "Article couldn't be entered?"))
  6265.     (kill-buffer dig)))))
  6266.  
  6267. (defun gnus-summary-read-document (n)
  6268.   "Open a new group based on the current article(s).
  6269. This will allow you to read digests and other similar
  6270. documents as newsgroups.
  6271. Obeys the standard process/prefix convention."
  6272.   (interactive "P")
  6273.   (let* ((articles (gnus-summary-work-articles n))
  6274.      (ogroup gnus-newsgroup-name)
  6275.      (params (append (gnus-info-params (gnus-get-info ogroup))
  6276.              (list (cons 'to-group ogroup))))
  6277.      article group egroup groups vgroup)
  6278.     (while (setq article (pop articles))
  6279.       (setq group (format "%s-%d" gnus-newsgroup-name article))
  6280.       (gnus-summary-remove-process-mark article)
  6281.       (when (gnus-summary-display-article article)
  6282.     (save-excursion
  6283.       (nnheader-temp-write nil
  6284.         (insert-buffer-substring gnus-original-article-buffer)
  6285.         ;; Remove some headers that may lead nndoc to make
  6286.         ;; the wrong guess.
  6287.         (message-narrow-to-head)
  6288.         (goto-char (point-min))
  6289.         (delete-matching-lines "^\\(Path\\):\\|^From ")
  6290.         (widen)
  6291.         (if (setq egroup
  6292.               (gnus-group-read-ephemeral-group
  6293.                group `(nndoc ,group (nndoc-address ,(current-buffer))
  6294.                      (nndoc-article-type guess))
  6295.                t nil t))
  6296.         (progn
  6297.           ;; Make all postings to this group go to the parent group.
  6298.           (nconc (gnus-info-params (gnus-get-info egroup))
  6299.              params)
  6300.           (push egroup groups))
  6301.           ;; Couldn't select this doc group.
  6302.           (gnus-error 3 "Article couldn't be entered"))))))
  6303.     ;; Now we have selected all the documents.
  6304.     (cond
  6305.      ((not groups)
  6306.       (error "None of the articles could be interpreted as documents"))
  6307.      ((gnus-group-read-ephemeral-group
  6308.        (setq vgroup (format
  6309.              "nnvirtual:%s-%s" gnus-newsgroup-name
  6310.              (format-time-string "%Y%m%dT%H%M%S" (current-time))))
  6311.        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
  6312.        t
  6313.        (cons (current-buffer) 'summary)))
  6314.      (t
  6315.       (error "Couldn't select virtual nndoc group")))))
  6316.  
  6317. (defun gnus-summary-isearch-article (&optional regexp-p)
  6318.   "Do incremental search forward on the current article.
  6319. If REGEXP-P (the prefix) is non-nil, do regexp isearch."
  6320.   (interactive "P")
  6321.   (gnus-set-global-variables)
  6322.   (gnus-summary-select-article)
  6323.   (gnus-configure-windows 'article)
  6324.   (gnus-eval-in-buffer-window gnus-article-buffer
  6325.     ;;(goto-char (point-min))
  6326.     (isearch-forward regexp-p)))
  6327.  
  6328. (defun gnus-summary-search-article-forward (regexp &optional backward)
  6329.   "Search for an article containing REGEXP forward.
  6330. If BACKWARD, search backward instead."
  6331.   (interactive
  6332.    (list (read-string
  6333.       (format "Search article %s (regexp%s): "
  6334.           (if current-prefix-arg "backward" "forward")
  6335.           (if gnus-last-search-regexp
  6336.               (concat ", default " gnus-last-search-regexp)
  6337.             "")))
  6338.      current-prefix-arg))
  6339.   (gnus-set-global-variables)
  6340.   (if (string-equal regexp "")
  6341.       (setq regexp (or gnus-last-search-regexp ""))
  6342.     (setq gnus-last-search-regexp regexp))
  6343.   (if (gnus-summary-search-article regexp backward)
  6344.       (gnus-summary-show-thread)
  6345.     (error "Search failed: \"%s\"" regexp)))
  6346.  
  6347. (defun gnus-summary-search-article-backward (regexp)
  6348.   "Search for an article containing REGEXP backward."
  6349.   (interactive
  6350.    (list (read-string
  6351.       (format "Search article backward (regexp%s): "
  6352.           (if gnus-last-search-regexp
  6353.               (concat ", default " gnus-last-search-regexp)
  6354.             "")))))
  6355.   (gnus-summary-search-article-forward regexp 'backward))
  6356.  
  6357. (defun gnus-summary-search-article (regexp &optional backward)
  6358.   "Search for an article containing REGEXP.
  6359. Optional argument BACKWARD means do search for backward.
  6360. `gnus-select-article-hook' is not called during the search."
  6361.   ;; We have to require this here to make sure that the following
  6362.   ;; dynamic binding isn't shadowed by autoloading.
  6363.   (require 'gnus-async)
  6364.   (let ((gnus-select-article-hook nil)    ;Disable hook.
  6365.     (gnus-article-display-hook nil)
  6366.     (gnus-mark-article-hook nil)    ;Inhibit marking as read.
  6367.     (gnus-use-article-prefetch nil)
  6368.     (gnus-xmas-force-redisplay nil)    ;Inhibit XEmacs redisplay.
  6369.     (gnus-use-trees nil)        ;Inhibit updating tree buffer.
  6370.     (sum (current-buffer))
  6371.     (found nil)
  6372.     point)
  6373.     (gnus-save-hidden-threads
  6374.       (gnus-summary-select-article)
  6375.       (set-buffer gnus-article-buffer)
  6376.       (when backward
  6377.     (forward-line -1))
  6378.       (while (not found)
  6379.     (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
  6380.     (if (if backward
  6381.         (re-search-backward regexp nil t)
  6382.           (re-search-forward regexp nil t))
  6383.         ;; We found the regexp.
  6384.         (progn
  6385.           (setq found 'found)
  6386.           (beginning-of-line)
  6387.           (set-window-start
  6388.            (get-buffer-window (current-buffer))
  6389.            (point))
  6390.           (forward-line 1)
  6391.           (set-buffer sum)
  6392.           (setq point (point)))
  6393.       ;; We didn't find it, so we go to the next article.
  6394.       (set-buffer sum)
  6395.       (setq found 'not)
  6396.       (while (eq found 'not)
  6397.         (if (not (if backward (gnus-summary-find-prev)
  6398.                (gnus-summary-find-next)))
  6399.         ;; No more articles.
  6400.         (setq found t)
  6401.           ;; Select the next article and adjust point.
  6402.           (unless (gnus-summary-article-sparse-p
  6403.                (gnus-summary-article-number))
  6404.         (setq found nil)
  6405.         (gnus-summary-select-article)
  6406.         (set-buffer gnus-article-buffer)
  6407.         (widen)
  6408.         (goto-char (if backward (point-max) (point-min))))))))
  6409.       (gnus-message 7 ""))
  6410.     ;; Return whether we found the regexp.
  6411.     (when (eq found 'found)
  6412.       (goto-char point)
  6413.       (gnus-summary-show-thread)
  6414.       (gnus-summary-goto-subject gnus-current-article)
  6415.       (gnus-summary-position-point)
  6416.       t)))
  6417.  
  6418. (defun gnus-summary-find-matching (header regexp &optional backward unread
  6419.                       not-case-fold)
  6420.   "Return a list of all articles that match REGEXP on HEADER.
  6421. The search stars on the current article and goes forwards unless
  6422. BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
  6423. If UNREAD is non-nil, only unread articles will
  6424. be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
  6425. in the comparisons."
  6426.   (let ((data (if (eq backward 'all) gnus-newsgroup-data
  6427.         (gnus-data-find-list
  6428.          (gnus-summary-article-number) (gnus-data-list backward))))
  6429.     (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
  6430.     (case-fold-search (not not-case-fold))
  6431.     articles d)
  6432.     (unless (fboundp (intern (concat "mail-header-" header)))
  6433.       (error "%s is not a valid header" header))
  6434.     (while data
  6435.       (setq d (car data))
  6436.       (and (or (not unread)        ; We want all articles...
  6437.            (gnus-data-unread-p d))    ; Or just unreads.
  6438.        (vectorp (gnus-data-header d)) ; It's not a pseudo.
  6439.        (string-match regexp (funcall func (gnus-data-header d))) ; Match.
  6440.        (push (gnus-data-number d) articles)) ; Success!
  6441.       (setq data (cdr data)))
  6442.     (nreverse articles)))
  6443.  
  6444. (defun gnus-summary-execute-command (header regexp command &optional backward)
  6445.   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
  6446. If HEADER is an empty string (or nil), the match is done on the entire
  6447. article.  If BACKWARD (the prefix) is non-nil, search backward instead."
  6448.   (interactive
  6449.    (list (let ((completion-ignore-case t))
  6450.        (completing-read
  6451.         "Header name: "
  6452.         (mapcar (lambda (string) (list string))
  6453.             '("Number" "Subject" "From" "Lines" "Date"
  6454.               "Message-ID" "Xref" "References" "Body"))
  6455.         nil 'require-match))
  6456.      (read-string "Regexp: ")
  6457.      (read-key-sequence "Command: ")
  6458.      current-prefix-arg))
  6459.   (when (equal header "Body")
  6460.     (setq header ""))
  6461.   (gnus-set-global-variables)
  6462.   ;; Hidden thread subtrees must be searched as well.
  6463.   (gnus-summary-show-all-threads)
  6464.   ;; We don't want to change current point nor window configuration.
  6465.   (save-excursion
  6466.     (save-window-excursion
  6467.       (gnus-message 6 "Executing %s..." (key-description command))
  6468.       ;; We'd like to execute COMMAND interactively so as to give arguments.
  6469.       (gnus-execute header regexp
  6470.             `(call-interactively ',(key-binding command))
  6471.             backward)
  6472.       (gnus-message 6 "Executing %s...done" (key-description command)))))
  6473.  
  6474. (defun gnus-summary-beginning-of-article ()
  6475.   "Scroll the article back to the beginning."
  6476.   (interactive)
  6477.   (gnus-set-global-variables)
  6478.   (gnus-summary-select-article)
  6479.   (gnus-configure-windows 'article)
  6480.   (gnus-eval-in-buffer-window gnus-article-buffer
  6481.     (widen)
  6482.     (goto-char (point-min))
  6483.     (when gnus-page-broken
  6484.       (gnus-narrow-to-page))))
  6485.  
  6486. (defun gnus-summary-end-of-article ()
  6487.   "Scroll to the end of the article."
  6488.   (interactive)
  6489.   (gnus-set-global-variables)
  6490.   (gnus-summary-select-article)
  6491.   (gnus-configure-windows 'article)
  6492.   (gnus-eval-in-buffer-window gnus-article-buffer
  6493.     (widen)
  6494.     (goto-char (point-max))
  6495.     (recenter -3)
  6496.     (when gnus-page-broken
  6497.       (gnus-narrow-to-page))))
  6498.  
  6499. (defun gnus-summary-print-article (&optional filename)
  6500.   "Generate and print a PostScript image of the article buffer.
  6501.  
  6502. If the optional argument FILENAME is nil, send the image to the printer.
  6503. If FILENAME is a string, save the PostScript image in a file with that
  6504. name.  If FILENAME is a number, prompt the user for the name of the file
  6505. to save in."
  6506.   (interactive (list (ps-print-preprint current-prefix-arg)))
  6507.   (gnus-summary-select-article)
  6508.   (gnus-eval-in-buffer-window gnus-article-buffer
  6509.     (let ((buffer (generate-new-buffer " *print*")))
  6510.       (unwind-protect
  6511.       (progn
  6512.         (copy-to-buffer buffer (point-min) (point-max))
  6513.         (set-buffer buffer)
  6514.         (gnus-article-delete-invisible-text)
  6515.         (run-hooks 'gnus-ps-print-hook)
  6516.         (ps-print-buffer-with-faces filename))
  6517.     (kill-buffer buffer)))))
  6518.  
  6519. (defun gnus-summary-show-article (&optional arg)
  6520.   "Force re-fetching of the current article.
  6521. If ARG (the prefix) is non-nil, show the raw article without any
  6522. article massaging functions being run."
  6523.   (interactive "P")
  6524.   (gnus-set-global-variables)
  6525.   (if (not arg)
  6526.       ;; Select the article the normal way.
  6527.       (gnus-summary-select-article nil 'force)
  6528.     ;; Bind the article treatment functions to nil.
  6529.     (let ((gnus-have-all-headers t)
  6530.       gnus-article-display-hook
  6531.       gnus-article-prepare-hook
  6532.       gnus-break-pages
  6533.       gnus-show-mime
  6534.       gnus-visual)
  6535.       (gnus-summary-select-article nil 'force)))
  6536.   (gnus-summary-goto-subject gnus-current-article)
  6537.   (gnus-summary-position-point))
  6538.  
  6539. (defun gnus-summary-verbose-headers (&optional arg)
  6540.   "Toggle permanent full header display.
  6541. If ARG is a positive number, turn header display on.
  6542. If ARG is a negative number, turn header display off."
  6543.   (interactive "P")
  6544.   (gnus-set-global-variables)
  6545.   (setq gnus-show-all-headers
  6546.     (cond ((or (not (numberp arg))
  6547.            (zerop arg))
  6548.            (not gnus-show-all-headers))
  6549.           ((natnump arg)
  6550.            t)))
  6551.   (gnus-summary-show-article))
  6552.  
  6553. (defun gnus-summary-toggle-header (&optional arg)
  6554.   "Show the headers if they are hidden, or hide them if they are shown.
  6555. If ARG is a positive number, show the entire header.
  6556. If ARG is a negative number, hide the unwanted header lines."
  6557.   (interactive "P")
  6558.   (gnus-set-global-variables)
  6559.   (save-excursion
  6560.     (set-buffer gnus-article-buffer)
  6561.     (let* ((buffer-read-only nil)
  6562.        (inhibit-point-motion-hooks t)
  6563.        (hidden (text-property-any
  6564.             (goto-char (point-min)) (search-forward "\n\n")
  6565.             'invisible t))
  6566.        e)
  6567.       (goto-char (point-min))
  6568.       (when (search-forward "\n\n" nil t)
  6569.     (delete-region (point-min) (1- (point))))
  6570.       (goto-char (point-min))
  6571.       (save-excursion
  6572.     (set-buffer gnus-original-article-buffer)
  6573.     (goto-char (point-min))
  6574.     (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
  6575.       (insert-buffer-substring gnus-original-article-buffer 1 e)
  6576.       (let ((article-inhibit-hiding t))
  6577.     (run-hooks 'gnus-article-display-hook))
  6578.       (when (or (not hidden) (and (numberp arg) (< arg 0)))
  6579.     (gnus-article-hide-headers)))))
  6580.  
  6581. (defun gnus-summary-show-all-headers ()
  6582.   "Make all header lines visible."
  6583.   (interactive)
  6584.   (gnus-set-global-variables)
  6585.   (gnus-article-show-all-headers))
  6586.  
  6587. (defun gnus-summary-toggle-mime (&optional arg)
  6588.   "Toggle MIME processing.
  6589. If ARG is a positive number, turn MIME processing on."
  6590.   (interactive "P")
  6591.   (gnus-set-global-variables)
  6592.   (setq gnus-show-mime
  6593.     (if (null arg) (not gnus-show-mime)
  6594.       (> (prefix-numeric-value arg) 0)))
  6595.   (gnus-summary-select-article t 'force))
  6596.  
  6597. (defun gnus-summary-caesar-message (&optional arg)
  6598.   "Caesar rotate the current article by 13.
  6599. The numerical prefix specifies how many places to rotate each letter
  6600. forward."
  6601.   (interactive "P")
  6602.   (gnus-set-global-variables)
  6603.   (gnus-summary-select-article)
  6604.   (let ((mail-header-separator ""))
  6605.     (gnus-eval-in-buffer-window gnus-article-buffer
  6606.       (save-restriction
  6607.     (widen)
  6608.     (let ((start (window-start))
  6609.           buffer-read-only)
  6610.       (message-caesar-buffer-body arg)
  6611.       (set-window-start (get-buffer-window (current-buffer)) start))))))
  6612.  
  6613. (defun gnus-summary-stop-page-breaking ()
  6614.   "Stop page breaking in the current article."
  6615.   (interactive)
  6616.   (gnus-set-global-variables)
  6617.   (gnus-summary-select-article)
  6618.   (gnus-eval-in-buffer-window gnus-article-buffer
  6619.     (widen)
  6620.     (when (gnus-visual-p 'page-marker)
  6621.       (let ((buffer-read-only nil))
  6622.     (gnus-remove-text-with-property 'gnus-prev)
  6623.     (gnus-remove-text-with-property 'gnus-next)))))
  6624.  
  6625. (defun gnus-summary-move-article (&optional n to-newsgroup
  6626.                         select-method action)
  6627.   "Move the current article to a different newsgroup.
  6628. If N is a positive number, move the N next articles.
  6629. If N is a negative number, move the N previous articles.
  6630. If N is nil and any articles have been marked with the process mark,
  6631. move those articles instead.
  6632. If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
  6633. If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
  6634. re-spool using this method.
  6635.  
  6636. For this function to work, both the current newsgroup and the
  6637. newsgroup that you want to move to have to support the `request-move'
  6638. and `request-accept' functions."
  6639.   (interactive "P")
  6640.   (unless action
  6641.     (setq action 'move))
  6642.   (gnus-set-global-variables)
  6643.   ;; Disable marking as read.
  6644.   (let (gnus-mark-article-hook)
  6645.     (save-window-excursion
  6646.       (gnus-summary-select-article)))
  6647.   ;; Check whether the source group supports the required functions.
  6648.   (cond ((and (eq action 'move)
  6649.           (not (gnus-check-backend-function
  6650.             'request-move-article gnus-newsgroup-name)))
  6651.      (error "The current group does not support article moving"))
  6652.     ((and (eq action 'crosspost)
  6653.           (not (gnus-check-backend-function
  6654.             'request-replace-article gnus-newsgroup-name)))
  6655.      (error "The current group does not support article editing")))
  6656.   (let ((articles (gnus-summary-work-articles n))
  6657.     (prefix (gnus-group-real-prefix gnus-newsgroup-name))
  6658.     (names '((move "Move" "Moving")
  6659.          (copy "Copy" "Copying")
  6660.          (crosspost "Crosspost" "Crossposting")))
  6661.     (copy-buf (save-excursion
  6662.             (nnheader-set-temp-buffer " *copy article*")))
  6663.     art-group to-method new-xref article to-groups)
  6664.     (unless (assq action names)
  6665.       (error "Unknown action %s" action))
  6666.     ;; Read the newsgroup name.
  6667.     (when (and (not to-newsgroup)
  6668.            (not select-method))
  6669.       (setq to-newsgroup
  6670.         (gnus-read-move-group-name
  6671.          (cadr (assq action names))
  6672.          (symbol-value (intern (format "gnus-current-%s-group" action)))
  6673.          articles prefix))
  6674.       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
  6675.     (setq to-method (or select-method
  6676.             (gnus-group-name-to-method to-newsgroup)))
  6677.     ;; Check the method we are to move this article to...
  6678.     (unless (gnus-check-backend-function
  6679.          'request-accept-article (car to-method))
  6680.       (error "%s does not support article copying" (car to-method)))
  6681.     (unless (gnus-check-server to-method)
  6682.       (error "Can't open server %s" (car to-method)))
  6683.     (gnus-message 6 "%s to %s: %s..."
  6684.           (caddr (assq action names))
  6685.           (or (car select-method) to-newsgroup) articles)
  6686.     (while articles
  6687.       (setq article (pop articles))
  6688.       (setq
  6689.        art-group
  6690.        (cond
  6691.     ;; Move the article.
  6692.     ((eq action 'move)
  6693.      ;; Remove this article from future suppression.
  6694.      (gnus-dup-unsuppress-article article)
  6695.      (gnus-request-move-article
  6696.       article            ; Article to move
  6697.       gnus-newsgroup-name        ; From newsgroup
  6698.       (nth 1 (gnus-find-method-for-group
  6699.           gnus-newsgroup-name)) ; Server
  6700.       (list 'gnus-request-accept-article
  6701.         to-newsgroup (list 'quote select-method)
  6702.         (not articles))        ; Accept form
  6703.       (not articles)))        ; Only save nov last time
  6704.     ;; Copy the article.
  6705.     ((eq action 'copy)
  6706.      (save-excursion
  6707.        (set-buffer copy-buf)
  6708.        (gnus-request-article-this-buffer article gnus-newsgroup-name)
  6709.        (gnus-request-accept-article
  6710.         to-newsgroup select-method (not articles))))
  6711.     ;; Crosspost the article.
  6712.     ((eq action 'crosspost)
  6713.      (let ((xref (message-tokenize-header
  6714.               (mail-header-xref (gnus-summary-article-header article))
  6715.               " ")))
  6716.        (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
  6717.                   ":" article))
  6718.        (unless xref
  6719.          (setq xref (list (system-name))))
  6720.        (setq new-xref
  6721.          (concat
  6722.           (mapconcat 'identity
  6723.                  (delete "Xref:" (delete new-xref xref))
  6724.                  " ")
  6725.           " " new-xref))
  6726.        (save-excursion
  6727.          (set-buffer copy-buf)
  6728.          ;; First put the article in the destination group.
  6729.          (gnus-request-article-this-buffer article gnus-newsgroup-name)
  6730.          (when (consp (setq art-group
  6731.                 (gnus-request-accept-article
  6732.                  to-newsgroup select-method (not articles))))
  6733.            (setq new-xref (concat new-xref " " (car art-group)
  6734.                       ":" (cdr art-group)))
  6735.            ;; Now we have the new Xrefs header, so we insert
  6736.            ;; it and replace the new article.
  6737.            (nnheader-replace-header "Xref" new-xref)
  6738.            (gnus-request-replace-article
  6739.         (cdr art-group) to-newsgroup (current-buffer))
  6740.            art-group))))))
  6741.       (cond
  6742.        ((not art-group)
  6743.     (gnus-message 1 "Couldn't %s article %s"
  6744.               (cadr (assq action names)) article))
  6745.        ((and (eq art-group 'junk)
  6746.          (eq action 'move))
  6747.     (gnus-summary-mark-article article gnus-canceled-mark)
  6748.     (gnus-message 4 "Deleted article %s" article))
  6749.        (t
  6750.     (let* ((entry
  6751.         (or
  6752.          (gnus-gethash (car art-group) gnus-newsrc-hashtb)
  6753.          (gnus-gethash
  6754.           (gnus-group-prefixed-name
  6755.            (car art-group)
  6756.            (or select-method
  6757.                (gnus-find-method-for-group to-newsgroup)))
  6758.           gnus-newsrc-hashtb)))
  6759.            (info (nth 2 entry))
  6760.            (to-group (gnus-info-group info)))
  6761.       ;; Update the group that has been moved to.
  6762.       (when (and info
  6763.              (memq action '(move copy)))
  6764.         (unless (member to-group to-groups)
  6765.           (push to-group to-groups))
  6766.  
  6767.         (unless (memq article gnus-newsgroup-unreads)
  6768.           (gnus-info-set-read
  6769.            info (gnus-add-to-range (gnus-info-read info)
  6770.                        (list (cdr art-group)))))
  6771.  
  6772.         ;; Copy any marks over to the new group.
  6773.         (let ((marks gnus-article-mark-lists)
  6774.           (to-article (cdr art-group)))
  6775.  
  6776.           ;; See whether the article is to be put in the cache.
  6777.           (when gnus-use-cache
  6778.         (gnus-cache-possibly-enter-article
  6779.          to-group to-article
  6780.          (let ((header (copy-sequence
  6781.                 (gnus-summary-article-header article))))
  6782.            (mail-header-set-number header to-article)
  6783.            header)
  6784.          (memq article gnus-newsgroup-marked)
  6785.          (memq article gnus-newsgroup-dormant)
  6786.          (memq article gnus-newsgroup-unreads)))
  6787.  
  6788.           (when (and (equal to-group gnus-newsgroup-name)
  6789.              (not (memq article gnus-newsgroup-unreads)))
  6790.         ;; Mark this article as read in this group.
  6791.         (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
  6792.         (setcdr (gnus-active to-group) to-article)
  6793.         (setcdr gnus-newsgroup-active to-article))
  6794.  
  6795.           (while marks
  6796.         (when (memq article (symbol-value
  6797.                      (intern (format "gnus-newsgroup-%s"
  6798.                              (caar marks)))))
  6799.           ;; If the other group is the same as this group,
  6800.           ;; then we have to add the mark to the list.
  6801.           (when (equal to-group gnus-newsgroup-name)
  6802.             (set (intern (format "gnus-newsgroup-%s" (caar marks)))
  6803.              (cons to-article
  6804.                    (symbol-value
  6805.                 (intern (format "gnus-newsgroup-%s"
  6806.                         (caar marks)))))))
  6807.           ;; Copy the marks to other group.
  6808.           (gnus-add-marked-articles
  6809.            to-group (cdar marks) (list to-article) info))
  6810.         (setq marks (cdr marks)))
  6811.  
  6812.           (gnus-dribble-enter
  6813.            (concat "(gnus-group-set-info '"
  6814.                (gnus-prin1-to-string (gnus-get-info to-group))
  6815.                ")"))))
  6816.  
  6817.       ;; Update the Xref header in this article to point to
  6818.       ;; the new crossposted article we have just created.
  6819.       (when (eq action 'crosspost)
  6820.         (save-excursion
  6821.           (set-buffer copy-buf)
  6822.           (gnus-request-article-this-buffer article gnus-newsgroup-name)
  6823.           (nnheader-replace-header "Xref" new-xref)
  6824.           (gnus-request-replace-article
  6825.            article gnus-newsgroup-name (current-buffer)))))
  6826.  
  6827.     (gnus-summary-goto-subject article)
  6828.     (when (eq action 'move)
  6829.       (gnus-summary-mark-article article gnus-canceled-mark))))
  6830.       (gnus-summary-remove-process-mark article))
  6831.     ;; Re-activate all groups that have been moved to.
  6832.     (while to-groups
  6833.       (save-excursion
  6834.     (set-buffer gnus-group-buffer)
  6835.     (when (gnus-group-goto-group (car to-groups) t)
  6836.       (gnus-group-get-new-news-this-group 1 t))
  6837.     (pop to-groups)))
  6838.  
  6839.     (gnus-kill-buffer copy-buf)
  6840.     (gnus-summary-position-point)
  6841.     (gnus-set-mode-line 'summary)))
  6842.  
  6843. (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
  6844.   "Move the current article to a different newsgroup.
  6845. If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
  6846. If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
  6847. re-spool using this method."
  6848.   (interactive "P")
  6849.   (gnus-summary-move-article n to-newsgroup select-method 'copy))
  6850.  
  6851. (defun gnus-summary-crosspost-article (&optional n)
  6852.   "Crosspost the current article to some other group."
  6853.   (interactive "P")
  6854.   (gnus-summary-move-article n nil nil 'crosspost))
  6855.  
  6856. (defcustom gnus-summary-respool-default-method nil
  6857.   "Default method for respooling an article.
  6858. If nil, use to the current newsgroup method."
  6859.   :type 'gnus-select-method-name
  6860.   :group 'gnus-summary-mail)
  6861.  
  6862. (defun gnus-summary-respool-article (&optional n method)
  6863.   "Respool the current article.
  6864. The article will be squeezed through the mail spooling process again,
  6865. which means that it will be put in some mail newsgroup or other
  6866. depending on `nnmail-split-methods'.
  6867. If N is a positive number, respool the N next articles.
  6868. If N is a negative number, respool the N previous articles.
  6869. If N is nil and any articles have been marked with the process mark,
  6870. respool those articles instead.
  6871.  
  6872. Respooling can be done both from mail groups and \"real\" newsgroups.
  6873. In the former case, the articles in question will be moved from the
  6874. current group into whatever groups they are destined to.  In the
  6875. latter case, they will be copied into the relevant groups."
  6876.   (interactive
  6877.    (list current-prefix-arg
  6878.      (let* ((methods (gnus-methods-using 'respool))
  6879.         (methname
  6880.          (symbol-name (or gnus-summary-respool-default-method
  6881.                   (car (gnus-find-method-for-group
  6882.                     gnus-newsgroup-name)))))
  6883.         (method
  6884.          (gnus-completing-read
  6885.           methname "What backend do you want to use when respooling?"
  6886.           methods nil t nil 'gnus-mail-method-history))
  6887.         ms)
  6888.        (cond
  6889.         ((zerop (length (setq ms (gnus-servers-using-backend
  6890.                       (intern method)))))
  6891.          (list (intern method) ""))
  6892.         ((= 1 (length ms))
  6893.          (car ms))
  6894.         (t
  6895.          (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
  6896.            (cdr (assoc (completing-read "Server name: " ms-alist nil t)
  6897.                ms-alist))))))))
  6898.   (gnus-set-global-variables)
  6899.   (unless method
  6900.     (error "No method given for respooling"))
  6901.   (if (assoc (symbol-name
  6902.           (car (gnus-find-method-for-group gnus-newsgroup-name)))
  6903.          (gnus-methods-using 'respool))
  6904.       (gnus-summary-move-article n nil method)
  6905.     (gnus-summary-copy-article n nil method)))
  6906.  
  6907. (defun gnus-summary-import-article (file)
  6908.   "Import a random file into a mail newsgroup."
  6909.   (interactive "fImport file: ")
  6910.   (gnus-set-global-variables)
  6911.   (let ((group gnus-newsgroup-name)
  6912.     (now (current-time))
  6913.     atts lines)
  6914.     (unless (gnus-check-backend-function 'request-accept-article group)
  6915.       (error "%s does not support article importing" group))
  6916.     (or (file-readable-p file)
  6917.     (not (file-regular-p file))
  6918.     (error "Can't read %s" file))
  6919.     (save-excursion
  6920.       (set-buffer (get-buffer-create " *import file*"))
  6921.       (buffer-disable-undo (current-buffer))
  6922.       (erase-buffer)
  6923.       (insert-file-contents file)
  6924.       (goto-char (point-min))
  6925.       (unless (nnheader-article-p)
  6926.     ;; This doesn't look like an article, so we fudge some headers.
  6927.     (setq atts (file-attributes file)
  6928.           lines (count-lines (point-min) (point-max)))
  6929.     (insert "From: " (read-string "From: ") "\n"
  6930.         "Subject: " (read-string "Subject: ") "\n"
  6931.         "Date: " (timezone-make-date-arpa-standard
  6932.               (current-time-string (nth 5 atts))
  6933.               (current-time-zone now)
  6934.               (current-time-zone now))
  6935.         "\n"
  6936.         "Message-ID: " (message-make-message-id) "\n"
  6937.         "Lines: " (int-to-string lines) "\n"
  6938.         "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
  6939.       (gnus-request-accept-article group nil t)
  6940.       (kill-buffer (current-buffer)))))
  6941.  
  6942. (defun gnus-summary-article-posted-p ()
  6943.   "Say whether the current (mail) article is available from `gnus-select-method' as well.
  6944. This will be the case if the article has both been mailed and posted."
  6945.   (interactive)
  6946.   (let ((id (mail-header-references (gnus-summary-article-header)))
  6947.     (gnus-override-method
  6948.      (or gnus-refer-article-method gnus-select-method)))
  6949.     (if (gnus-request-head id "")
  6950.     (gnus-message 2 "The current message was found on %s"
  6951.               gnus-override-method)
  6952.       (gnus-message 2 "The current message couldn't be found on %s"
  6953.             gnus-override-method)
  6954.       nil)))
  6955.  
  6956. (defun gnus-summary-expire-articles (&optional now)
  6957.   "Expire all articles that are marked as expirable in the current group."
  6958.   (interactive)
  6959.   (gnus-set-global-variables)
  6960.   (when (gnus-check-backend-function
  6961.      'request-expire-articles gnus-newsgroup-name)
  6962.     ;; This backend supports expiry.
  6963.     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
  6964.        (expirable (if total
  6965.               (progn
  6966.                 ;; We need to update the info for
  6967.                 ;; this group for `gnus-list-of-read-articles'
  6968.                 ;; to give us the right answer.
  6969.                 (run-hooks 'gnus-exit-group-hook)
  6970.                 (gnus-summary-update-info)
  6971.                 (gnus-list-of-read-articles gnus-newsgroup-name))
  6972.             (setq gnus-newsgroup-expirable
  6973.                   (sort gnus-newsgroup-expirable '<))))
  6974.        (expiry-wait (if now 'immediate
  6975.               (gnus-group-find-parameter
  6976.                gnus-newsgroup-name 'expiry-wait)))
  6977.        es)
  6978.       (when expirable
  6979.     ;; There are expirable articles in this group, so we run them
  6980.     ;; through the expiry process.
  6981.     (gnus-message 6 "Expiring articles...")
  6982.     ;; The list of articles that weren't expired is returned.
  6983.     (if expiry-wait
  6984.         (let ((nnmail-expiry-wait-function nil)
  6985.           (nnmail-expiry-wait expiry-wait))
  6986.           (setq es (gnus-request-expire-articles
  6987.             expirable gnus-newsgroup-name)))
  6988.       (setq es (gnus-request-expire-articles
  6989.             expirable gnus-newsgroup-name)))
  6990.     (unless total
  6991.       (setq gnus-newsgroup-expirable es))
  6992.     ;; We go through the old list of expirable, and mark all
  6993.     ;; really expired articles as nonexistent.
  6994.     (unless (eq es expirable)    ;If nothing was expired, we don't mark.
  6995.       (let ((gnus-use-cache nil))
  6996.         (while expirable
  6997.           (unless (memq (car expirable) es)
  6998.         (when (gnus-data-find (car expirable))
  6999.           (gnus-summary-mark-article
  7000.            (car expirable) gnus-canceled-mark)))
  7001.           (setq expirable (cdr expirable)))))
  7002.     (gnus-message 6 "Expiring articles...done")))))
  7003.  
  7004. (defun gnus-summary-expire-articles-now ()
  7005.   "Expunge all expirable articles in the current group.
  7006. This means that *all* articles that are marked as expirable will be
  7007. deleted forever, right now."
  7008.   (interactive)
  7009.   (gnus-set-global-variables)
  7010.   (or gnus-expert-user
  7011.       (gnus-yes-or-no-p
  7012.        "Are you really, really, really sure you want to delete all these messages? ")
  7013.       (error "Phew!"))
  7014.   (gnus-summary-expire-articles t))
  7015.  
  7016. ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
  7017. (defun gnus-summary-delete-article (&optional n)
  7018.   "Delete the N next (mail) articles.
  7019. This command actually deletes articles.     This is not a marking
  7020. command.  The article will disappear forever from your life, never to
  7021. return.
  7022. If N is negative, delete backwards.
  7023. If N is nil and articles have been marked with the process mark,
  7024. delete these instead."
  7025.   (interactive "P")
  7026.   (gnus-set-global-variables)
  7027.   (unless (gnus-check-backend-function 'request-expire-articles
  7028.                        gnus-newsgroup-name)
  7029.     (error "The current newsgroup does not support article deletion"))
  7030.   ;; Compute the list of articles to delete.
  7031.   (let ((articles (gnus-summary-work-articles n))
  7032.     not-deleted)
  7033.     (if (and gnus-novice-user
  7034.          (not (gnus-yes-or-no-p
  7035.            (format "Do you really want to delete %s forever? "
  7036.                (if (> (length articles) 1)
  7037.                    (format "these %s articles" (length articles))
  7038.                  "this article")))))
  7039.     ()
  7040.       ;; Delete the articles.
  7041.       (setq not-deleted (gnus-request-expire-articles
  7042.              articles gnus-newsgroup-name 'force))
  7043.       (while articles
  7044.     (gnus-summary-remove-process-mark (car articles))
  7045.     ;; The backend might not have been able to delete the article
  7046.     ;; after all.
  7047.     (unless (memq (car articles) not-deleted)
  7048.       (gnus-summary-mark-article (car articles) gnus-canceled-mark))
  7049.     (setq articles (cdr articles)))
  7050.       (when not-deleted
  7051.     (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
  7052.     (gnus-summary-position-point)
  7053.     (gnus-set-mode-line 'summary)
  7054.     not-deleted))
  7055.  
  7056. (defun gnus-summary-edit-article (&optional force)
  7057.   "Edit the current article.
  7058. This will have permanent effect only in mail groups.
  7059. If FORCE is non-nil, allow editing of articles even in read-only
  7060. groups."
  7061.   (interactive "P")
  7062.   (save-excursion
  7063.     (set-buffer gnus-summary-buffer)
  7064.     (gnus-set-global-variables)
  7065.     (when (and (not force)
  7066.            (gnus-group-read-only-p))
  7067.       (error "The current newsgroup does not support article editing"))
  7068.     ;; Select article if needed.
  7069.     (unless (eq (gnus-summary-article-number)
  7070.         gnus-current-article)
  7071.       (gnus-summary-select-article t))
  7072.     (gnus-article-date-original)
  7073.     (gnus-article-edit-article
  7074.      `(lambda ()
  7075.     (gnus-summary-edit-article-done
  7076.      ,(or (mail-header-references gnus-current-headers) "")
  7077.      ,(gnus-group-read-only-p) ,gnus-summary-buffer)))))
  7078.  
  7079. (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
  7080.  
  7081. (defun gnus-summary-edit-article-done (&optional references read-only buffer)
  7082.   "Make edits to the current article permanent."
  7083.   (interactive)
  7084.   ;; Replace the article.
  7085.   (if (and (not read-only)
  7086.        (not (gnus-request-replace-article
  7087.          (cdr gnus-article-current) (car gnus-article-current)
  7088.          (current-buffer))))
  7089.       (error "Couldn't replace article")
  7090.     ;; Update the summary buffer.
  7091.     (if (and references
  7092.          (equal (message-tokenize-header references " ")
  7093.             (message-tokenize-header
  7094.              (or (message-fetch-field "references") "") " ")))
  7095.     ;; We only have to update this line.
  7096.     (save-excursion
  7097.       (save-restriction
  7098.         (message-narrow-to-head)
  7099.         (let ((head (buffer-string))
  7100.           header)
  7101.           (nnheader-temp-write nil
  7102.         (insert (format "211 %d Article retrieved.\n"
  7103.                 (cdr gnus-article-current)))
  7104.         (insert head)
  7105.         (insert ".\n")
  7106.         (let ((nntp-server-buffer (current-buffer)))
  7107.           (setq header (car (gnus-get-newsgroup-headers
  7108.                      (save-excursion
  7109.                        (set-buffer gnus-summary-buffer)
  7110.                        gnus-newsgroup-dependencies)
  7111.                      t))))
  7112.         (save-excursion
  7113.           (set-buffer gnus-summary-buffer)
  7114.           (gnus-data-set-header
  7115.            (gnus-data-find (cdr gnus-article-current))
  7116.            header)
  7117.           (gnus-summary-update-article-line
  7118.            (cdr gnus-article-current) header))))))
  7119.       ;; Update threads.
  7120.       (set-buffer (or buffer gnus-summary-buffer))
  7121.       (gnus-summary-update-article (cdr gnus-article-current)))
  7122.     ;; Prettify the article buffer again.
  7123.     (save-excursion
  7124.       (set-buffer gnus-article-buffer)
  7125.       (run-hooks 'gnus-article-display-hook)
  7126.       (set-buffer gnus-original-article-buffer)
  7127.       (gnus-request-article
  7128.        (cdr gnus-article-current) (car gnus-article-current) (current-buffer)))
  7129.     ;; Prettify the summary buffer line.
  7130.     (when (gnus-visual-p 'summary-highlight 'highlight)
  7131.       (run-hooks 'gnus-visual-mark-article-hook))))
  7132.  
  7133. (defun gnus-summary-edit-wash (key)
  7134.   "Perform editing command in the article buffer."
  7135.   (interactive
  7136.    (list
  7137.     (progn
  7138.       (message "%s" (concat (this-command-keys) "- "))
  7139.       (read-char))))
  7140.   (message "")
  7141.   (gnus-summary-edit-article)
  7142.   (execute-kbd-macro (concat (this-command-keys) key))
  7143.   (gnus-article-edit-done))
  7144.  
  7145. ;;; Respooling
  7146.  
  7147. (defun gnus-summary-respool-query (&optional silent)
  7148.   "Query where the respool algorithm would put this article."
  7149.   (interactive)
  7150.   (gnus-set-global-variables)
  7151.   (let (gnus-mark-article-hook)
  7152.     (gnus-summary-select-article)
  7153.     (save-excursion
  7154.       (set-buffer gnus-original-article-buffer)
  7155.       (save-restriction
  7156.     (message-narrow-to-head)
  7157.     (let ((groups (nnmail-article-group 'identity)))
  7158.       (unless silent
  7159.         (if groups
  7160.         (message "This message would go to %s"
  7161.              (mapconcat 'car groups ", "))
  7162.           (message "This message would go to no groups"))
  7163.         groups))))))
  7164.  
  7165. ;; Summary marking commands.
  7166.  
  7167. (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
  7168.   "Mark articles which has the same subject as read, and then select the next.
  7169. If UNMARK is positive, remove any kind of mark.
  7170. If UNMARK is negative, tick articles."
  7171.   (interactive "P")
  7172.   (gnus-set-global-variables)
  7173.   (when unmark
  7174.     (setq unmark (prefix-numeric-value unmark)))
  7175.   (let ((count
  7176.      (gnus-summary-mark-same-subject
  7177.       (gnus-summary-article-subject) unmark)))
  7178.     ;; Select next unread article.  If auto-select-same mode, should
  7179.     ;; select the first unread article.
  7180.     (gnus-summary-next-article t (and gnus-auto-select-same
  7181.                       (gnus-summary-article-subject)))
  7182.     (gnus-message 7 "%d article%s marked as %s"
  7183.           count (if (= count 1) " is" "s are")
  7184.           (if unmark "unread" "read"))))
  7185.  
  7186. (defun gnus-summary-kill-same-subject (&optional unmark)
  7187.   "Mark articles which has the same subject as read.
  7188. If UNMARK is positive, remove any kind of mark.
  7189. If UNMARK is negative, tick articles."
  7190.   (interactive "P")
  7191.   (gnus-set-global-variables)
  7192.   (when unmark
  7193.     (setq unmark (prefix-numeric-value unmark)))
  7194.   (let ((count
  7195.      (gnus-summary-mark-same-subject
  7196.       (gnus-summary-article-subject) unmark)))
  7197.     ;; If marked as read, go to next unread subject.
  7198.     (when (null unmark)
  7199.       ;; Go to next unread subject.
  7200.       (gnus-summary-next-subject 1 t))
  7201.     (gnus-message 7 "%d articles are marked as %s"
  7202.           count (if unmark "unread" "read"))))
  7203.  
  7204. (defun gnus-summary-mark-same-subject (subject &optional unmark)
  7205.   "Mark articles with same SUBJECT as read, and return marked number.
  7206. If optional argument UNMARK is positive, remove any kinds of marks.
  7207. If optional argument UNMARK is negative, mark articles as unread instead."
  7208.   (let ((count 1))
  7209.     (save-excursion
  7210.       (cond
  7211.        ((null unmark)            ; Mark as read.
  7212.     (while (and
  7213.         (progn
  7214.           (gnus-summary-mark-article-as-read gnus-killed-mark)
  7215.           (gnus-summary-show-thread) t)
  7216.         (gnus-summary-find-subject subject))
  7217.       (setq count (1+ count))))
  7218.        ((> unmark 0)            ; Tick.
  7219.     (while (and
  7220.         (progn
  7221.           (gnus-summary-mark-article-as-unread gnus-ticked-mark)
  7222.           (gnus-summary-show-thread) t)
  7223.         (gnus-summary-find-subject subject))
  7224.       (setq count (1+ count))))
  7225.        (t                ; Mark as unread.
  7226.     (while (and
  7227.         (progn
  7228.           (gnus-summary-mark-article-as-unread gnus-unread-mark)
  7229.           (gnus-summary-show-thread) t)
  7230.         (gnus-summary-find-subject subject))
  7231.       (setq count (1+ count)))))
  7232.       (gnus-set-mode-line 'summary)
  7233.       ;; Return the number of marked articles.
  7234.       count)))
  7235.  
  7236. (defun gnus-summary-mark-as-processable (n &optional unmark)
  7237.   "Set the process mark on the next N articles.
  7238. If N is negative, mark backward instead.  If UNMARK is non-nil, remove
  7239. the process mark instead.  The difference between N and the actual
  7240. number of articles marked is returned."
  7241.   (interactive "p")
  7242.   (gnus-set-global-variables)
  7243.   (let ((backward (< n 0))
  7244.     (n (abs n)))
  7245.     (while (and
  7246.         (> n 0)
  7247.         (if unmark
  7248.         (gnus-summary-remove-process-mark
  7249.          (gnus-summary-article-number))
  7250.           (gnus-summary-set-process-mark (gnus-summary-article-number)))
  7251.         (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
  7252.       (setq n (1- n)))
  7253.     (when (/= 0 n)
  7254.       (gnus-message 7 "No more articles"))
  7255.     (gnus-summary-recenter)
  7256.     (gnus-summary-position-point)
  7257.     n))
  7258.  
  7259. (defun gnus-summary-unmark-as-processable (n)
  7260.   "Remove the process mark from the next N articles.
  7261. If N is negative, mark backward instead.  The difference between N and
  7262. the actual number of articles marked is returned."
  7263.   (interactive "p")
  7264.   (gnus-set-global-variables)
  7265.   (gnus-summary-mark-as-processable n t))
  7266.  
  7267. (defun gnus-summary-unmark-all-processable ()
  7268.   "Remove the process mark from all articles."
  7269.   (interactive)
  7270.   (gnus-set-global-variables)
  7271.   (save-excursion
  7272.     (while gnus-newsgroup-processable
  7273.       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
  7274.   (gnus-summary-position-point))
  7275.  
  7276. (defun gnus-summary-mark-as-expirable (n)
  7277.   "Mark N articles forward as expirable.
  7278. If N is negative, mark backward instead.  The difference between N and
  7279. the actual number of articles marked is returned."
  7280.   (interactive "p")
  7281.   (gnus-set-global-variables)
  7282.   (gnus-summary-mark-forward n gnus-expirable-mark))
  7283.  
  7284. (defun gnus-summary-mark-article-as-replied (article)
  7285.   "Mark ARTICLE replied and update the summary line."
  7286.   (push article gnus-newsgroup-replied)
  7287.   (let ((buffer-read-only nil))
  7288.     (when (gnus-summary-goto-subject article)
  7289.       (gnus-summary-update-secondary-mark article))))
  7290.  
  7291. (defun gnus-summary-set-bookmark (article)
  7292.   "Set a bookmark in current article."
  7293.   (interactive (list (gnus-summary-article-number)))
  7294.   (gnus-set-global-variables)
  7295.   (when (or (not (get-buffer gnus-article-buffer))
  7296.         (not gnus-current-article)
  7297.         (not gnus-article-current)
  7298.         (not (equal gnus-newsgroup-name (car gnus-article-current))))
  7299.     (error "No current article selected"))
  7300.   ;; Remove old bookmark, if one exists.
  7301.   (let ((old (assq article gnus-newsgroup-bookmarks)))
  7302.     (when old
  7303.       (setq gnus-newsgroup-bookmarks
  7304.         (delq old gnus-newsgroup-bookmarks))))
  7305.   ;; Set the new bookmark, which is on the form
  7306.   ;; (article-number . line-number-in-body).
  7307.   (push
  7308.    (cons article
  7309.      (save-excursion
  7310.        (set-buffer gnus-article-buffer)
  7311.        (count-lines
  7312.         (min (point)
  7313.          (save-excursion
  7314.            (goto-char (point-min))
  7315.            (search-forward "\n\n" nil t)
  7316.            (point)))
  7317.         (point))))
  7318.    gnus-newsgroup-bookmarks)
  7319.   (gnus-message 6 "A bookmark has been added to the current article."))
  7320.  
  7321. (defun gnus-summary-remove-bookmark (article)
  7322.   "Remove the bookmark from the current article."
  7323.   (interactive (list (gnus-summary-article-number)))
  7324.   (gnus-set-global-variables)
  7325.   ;; Remove old bookmark, if one exists.
  7326.   (let ((old (assq article gnus-newsgroup-bookmarks)))
  7327.     (if old
  7328.     (progn
  7329.       (setq gnus-newsgroup-bookmarks
  7330.         (delq old gnus-newsgroup-bookmarks))
  7331.       (gnus-message 6 "Removed bookmark."))
  7332.       (gnus-message 6 "No bookmark in current article."))))
  7333.  
  7334. ;; Suggested by Daniel Quinlan <quinlan@best.com>.
  7335. (defun gnus-summary-mark-as-dormant (n)
  7336.   "Mark N articles forward as dormant.
  7337. If N is negative, mark backward instead.  The difference between N and
  7338. the actual number of articles marked is returned."
  7339.   (interactive "p")
  7340.   (gnus-set-global-variables)
  7341.   (gnus-summary-mark-forward n gnus-dormant-mark))
  7342.  
  7343. (defun gnus-summary-set-process-mark (article)
  7344.   "Set the process mark on ARTICLE and update the summary line."
  7345.   (setq gnus-newsgroup-processable
  7346.     (cons article
  7347.           (delq article gnus-newsgroup-processable)))
  7348.   (when (gnus-summary-goto-subject article)
  7349.     (gnus-summary-show-thread)
  7350.     (gnus-summary-update-secondary-mark article)))
  7351.  
  7352. (defun gnus-summary-remove-process-mark (article)
  7353.   "Remove the process mark from ARTICLE and update the summary line."
  7354.   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
  7355.   (when (gnus-summary-goto-subject article)
  7356.     (gnus-summary-show-thread)
  7357.     (gnus-summary-update-secondary-mark article)))
  7358.  
  7359. (defun gnus-summary-set-saved-mark (article)
  7360.   "Set the process mark on ARTICLE and update the summary line."
  7361.   (push article gnus-newsgroup-saved)
  7362.   (when (gnus-summary-goto-subject article)
  7363.     (gnus-summary-update-secondary-mark article)))
  7364.  
  7365. (defun gnus-summary-mark-forward (n &optional mark no-expire)
  7366.   "Mark N articles as read forwards.
  7367. If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
  7368. The difference between N and the actual number of articles marked is
  7369. returned."
  7370.   (interactive "p")
  7371.   (gnus-set-global-variables)
  7372.   (let ((backward (< n 0))
  7373.     (gnus-summary-goto-unread
  7374.      (and gnus-summary-goto-unread
  7375.           (not (eq gnus-summary-goto-unread 'never))
  7376.           (not (memq mark (list gnus-unread-mark
  7377.                     gnus-ticked-mark gnus-dormant-mark)))))
  7378.     (n (abs n))
  7379.     (mark (or mark gnus-del-mark)))
  7380.     (while (and (> n 0)
  7381.         (gnus-summary-mark-article nil mark no-expire)
  7382.         (zerop (gnus-summary-next-subject
  7383.             (if backward -1 1)
  7384.             (and gnus-summary-goto-unread
  7385.                  (not (eq gnus-summary-goto-unread 'never)))
  7386.             t)))
  7387.       (setq n (1- n)))
  7388.     (when (/= 0 n)
  7389.       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
  7390.     (gnus-summary-recenter)
  7391.     (gnus-summary-position-point)
  7392.     (gnus-set-mode-line 'summary)
  7393.     n))
  7394.  
  7395. (defun gnus-summary-mark-article-as-read (mark)
  7396.   "Mark the current article quickly as read with MARK."
  7397.   (let ((article (gnus-summary-article-number)))
  7398.     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
  7399.     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
  7400.     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
  7401.     (push (cons article mark) gnus-newsgroup-reads)
  7402.     ;; Possibly remove from cache, if that is used.
  7403.     (when gnus-use-cache
  7404.       (gnus-cache-enter-remove-article article))
  7405.     ;; Allow the backend to change the mark.
  7406.     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
  7407.     ;; Check for auto-expiry.
  7408.     (when (and gnus-newsgroup-auto-expire
  7409.            (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
  7410.            (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
  7411.            (= mark gnus-ancient-mark)
  7412.            (= mark gnus-read-mark) (= mark gnus-souped-mark)
  7413.            (= mark gnus-duplicate-mark)))
  7414.       (setq mark gnus-expirable-mark)
  7415.       (push article gnus-newsgroup-expirable))
  7416.     ;; Set the mark in the buffer.
  7417.     (gnus-summary-update-mark mark 'unread)
  7418.     t))
  7419.  
  7420. (defun gnus-summary-mark-article-as-unread (mark)
  7421.   "Mark the current article quickly as unread with MARK."
  7422.   (let ((article (gnus-summary-article-number)))
  7423.     (if (< article 0)
  7424.     (gnus-error 1 "Unmarkable article")
  7425.       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
  7426.       (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
  7427.       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
  7428.       (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
  7429.       (cond ((= mark gnus-ticked-mark)
  7430.          (push article gnus-newsgroup-marked))
  7431.         ((= mark gnus-dormant-mark)
  7432.          (push article gnus-newsgroup-dormant))
  7433.         (t
  7434.          (push article gnus-newsgroup-unreads)))
  7435.       (setq gnus-newsgroup-reads
  7436.         (delq (assq article gnus-newsgroup-reads)
  7437.           gnus-newsgroup-reads))
  7438.  
  7439.       ;; See whether the article is to be put in the cache.
  7440.       (and gnus-use-cache
  7441.        (vectorp (gnus-summary-article-header article))
  7442.        (save-excursion
  7443.          (gnus-cache-possibly-enter-article
  7444.           gnus-newsgroup-name article
  7445.           (gnus-summary-article-header article)
  7446.           (= mark gnus-ticked-mark)
  7447.           (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
  7448.  
  7449.       ;; Fix the mark.
  7450.       (gnus-summary-update-mark mark 'unread))
  7451.     t))
  7452.  
  7453. (defun gnus-summary-mark-article (&optional article mark no-expire)
  7454.   "Mark ARTICLE with MARK.  MARK can be any character.
  7455. Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
  7456. `??' (dormant) and `?E' (expirable).
  7457. If MARK is nil, then the default character `?D' is used.
  7458. If ARTICLE is nil, then the article on the current line will be
  7459. marked."
  7460.   ;; The mark might be a string.
  7461.   (when (stringp mark)
  7462.     (setq mark (aref mark 0)))
  7463.   ;; If no mark is given, then we check auto-expiring.
  7464.   (and (not no-expire)
  7465.        gnus-newsgroup-auto-expire
  7466.        (or (not mark)
  7467.        (and (gnus-characterp mark)
  7468.         (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
  7469.             (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
  7470.             (= mark gnus-read-mark) (= mark gnus-souped-mark)
  7471.             (= mark gnus-duplicate-mark))))
  7472.        (setq mark gnus-expirable-mark))
  7473.   (let* ((mark (or mark gnus-del-mark))
  7474.      (article (or article (gnus-summary-article-number))))
  7475.     (unless article
  7476.       (error "No article on current line"))
  7477.     (if (or (= mark gnus-unread-mark)
  7478.         (= mark gnus-ticked-mark)
  7479.         (= mark gnus-dormant-mark))
  7480.     (gnus-mark-article-as-unread article mark)
  7481.       (gnus-mark-article-as-read article mark))
  7482.  
  7483.     ;; See whether the article is to be put in the cache.
  7484.     (and gnus-use-cache
  7485.      (not (= mark gnus-canceled-mark))
  7486.      (vectorp (gnus-summary-article-header article))
  7487.      (save-excursion
  7488.        (gnus-cache-possibly-enter-article
  7489.         gnus-newsgroup-name article
  7490.         (gnus-summary-article-header article)
  7491.         (= mark gnus-ticked-mark)
  7492.         (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
  7493.  
  7494.     (when (gnus-summary-goto-subject article nil t)
  7495.       (let ((buffer-read-only nil))
  7496.     (gnus-summary-show-thread)
  7497.     ;; Fix the mark.
  7498.     (gnus-summary-update-mark mark 'unread)
  7499.     t))))
  7500.  
  7501. (defun gnus-summary-update-secondary-mark (article)
  7502.   "Update the secondary (read, process, cache) mark."
  7503.   (gnus-summary-update-mark
  7504.    (cond ((memq article gnus-newsgroup-processable)
  7505.       gnus-process-mark)
  7506.      ((memq article gnus-newsgroup-cached)
  7507.       gnus-cached-mark)
  7508.      ((memq article gnus-newsgroup-replied)
  7509.       gnus-replied-mark)
  7510.      ((memq article gnus-newsgroup-saved)
  7511.       gnus-saved-mark)
  7512.      (t gnus-unread-mark))
  7513.    'replied)
  7514.   (when (gnus-visual-p 'summary-highlight 'highlight)
  7515.     (run-hooks 'gnus-summary-update-hook))
  7516.   t)
  7517.  
  7518. (defun gnus-summary-update-mark (mark type)
  7519.   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
  7520.         (buffer-read-only nil))
  7521.     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
  7522.     (when (looking-at "\r")
  7523.       (incf forward))
  7524.     (when (and forward
  7525.                (<= (+ forward (point)) (point-max)))
  7526.       ;; Go to the right position on the line.
  7527.       (goto-char (+ forward (point)))
  7528.       ;; Replace the old mark with the new mark.
  7529.       (subst-char-in-region (point) (1+ (point)) (following-char) mark)
  7530.       ;; Optionally update the marks by some user rule.
  7531.       (when (eq type 'unread)
  7532.         (gnus-data-set-mark
  7533.          (gnus-data-find (gnus-summary-article-number)) mark)
  7534.         (gnus-summary-update-line (eq mark gnus-unread-mark))))))
  7535.  
  7536. (defun gnus-mark-article-as-read (article &optional mark)
  7537.   "Enter ARTICLE in the pertinent lists and remove it from others."
  7538.   ;; Make the article expirable.
  7539.   (let ((mark (or mark gnus-del-mark)))
  7540.     (if (= mark gnus-expirable-mark)
  7541.     (push article gnus-newsgroup-expirable)
  7542.       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
  7543.     ;; Remove from unread and marked lists.
  7544.     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
  7545.     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
  7546.     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
  7547.     (push (cons article mark) gnus-newsgroup-reads)
  7548.     ;; Possibly remove from cache, if that is used.
  7549.     (when gnus-use-cache
  7550.       (gnus-cache-enter-remove-article article))))
  7551.  
  7552. (defun gnus-mark-article-as-unread (article &optional mark)
  7553.   "Enter ARTICLE in the pertinent lists and remove it from others."
  7554.   (let ((mark (or mark gnus-ticked-mark)))
  7555.     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
  7556.       gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
  7557.       gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
  7558.       gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
  7559.  
  7560.     ;; Unsuppress duplicates?
  7561.     (when gnus-suppress-duplicates
  7562.       (gnus-dup-unsuppress-article article))
  7563.  
  7564.     (cond ((= mark gnus-ticked-mark)
  7565.        (push article gnus-newsgroup-marked))
  7566.       ((= mark gnus-dormant-mark)
  7567.        (push article gnus-newsgroup-dormant))
  7568.       (t
  7569.        (push article gnus-newsgroup-unreads)))
  7570.     (setq gnus-newsgroup-reads
  7571.       (delq (assq article gnus-newsgroup-reads)
  7572.         gnus-newsgroup-reads))))
  7573.  
  7574. (defalias 'gnus-summary-mark-as-unread-forward
  7575.   'gnus-summary-tick-article-forward)
  7576. (make-obsolete 'gnus-summary-mark-as-unread-forward
  7577.            'gnus-summary-tick-article-forward)
  7578. (defun gnus-summary-tick-article-forward (n)
  7579.   "Tick N articles forwards.
  7580. If N is negative, tick backwards instead.
  7581. The difference between N and the number of articles ticked is returned."
  7582.   (interactive "p")
  7583.   (gnus-summary-mark-forward n gnus-ticked-mark))
  7584.  
  7585. (defalias 'gnus-summary-mark-as-unread-backward
  7586.   'gnus-summary-tick-article-backward)
  7587. (make-obsolete 'gnus-summary-mark-as-unread-backward
  7588.            'gnus-summary-tick-article-backward)
  7589. (defun gnus-summary-tick-article-backward (n)
  7590.   "Tick N articles backwards.
  7591. The difference between N and the number of articles ticked is returned."
  7592.   (interactive "p")
  7593.   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
  7594.  
  7595. (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
  7596. (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
  7597. (defun gnus-summary-tick-article (&optional article clear-mark)
  7598.   "Mark current article as unread.
  7599. Optional 1st argument ARTICLE specifies article number to be marked as unread.
  7600. Optional 2nd argument CLEAR-MARK remove any kinds of mark."
  7601.   (interactive)
  7602.   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
  7603.                        gnus-ticked-mark)))
  7604.  
  7605. (defun gnus-summary-mark-as-read-forward (n)
  7606.   "Mark N articles as read forwards.
  7607. If N is negative, mark backwards instead.
  7608. The difference between N and the actual number of articles marked is
  7609. returned."
  7610.   (interactive "p")
  7611.   (gnus-summary-mark-forward n gnus-del-mark t))
  7612.  
  7613. (defun gnus-summary-mark-as-read-backward (n)
  7614.   "Mark the N articles as read backwards.
  7615. The difference between N and the actual number of articles marked is
  7616. returned."
  7617.   (interactive "p")
  7618.   (gnus-summary-mark-forward (- n) gnus-del-mark t))
  7619.  
  7620. (defun gnus-summary-mark-as-read (&optional article mark)
  7621.   "Mark current article as read.
  7622. ARTICLE specifies the article to be marked as read.
  7623. MARK specifies a string to be inserted at the beginning of the line."
  7624.   (gnus-summary-mark-article article mark))
  7625.  
  7626. (defun gnus-summary-clear-mark-forward (n)
  7627.   "Clear marks from N articles forward.
  7628. If N is negative, clear backward instead.
  7629. The difference between N and the number of marks cleared is returned."
  7630.   (interactive "p")
  7631.   (gnus-summary-mark-forward n gnus-unread-mark))
  7632.  
  7633. (defun gnus-summary-clear-mark-backward (n)
  7634.   "Clear marks from N articles backward.
  7635. The difference between N and the number of marks cleared is returned."
  7636.   (interactive "p")
  7637.   (gnus-summary-mark-forward (- n) gnus-unread-mark))
  7638.  
  7639. (defun gnus-summary-mark-unread-as-read ()
  7640.   "Intended to be used by `gnus-summary-mark-article-hook'."
  7641.   (when (memq gnus-current-article gnus-newsgroup-unreads)
  7642.     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
  7643.  
  7644. (defun gnus-summary-mark-read-and-unread-as-read ()
  7645.   "Intended to be used by `gnus-summary-mark-article-hook'."
  7646.   (let ((mark (gnus-summary-article-mark)))
  7647.     (when (or (gnus-unread-mark-p mark)
  7648.           (gnus-read-mark-p mark))
  7649.       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
  7650.  
  7651. (defun gnus-summary-mark-region-as-read (point mark all)
  7652.   "Mark all unread articles between point and mark as read.
  7653. If given a prefix, mark all articles between point and mark as read,
  7654. even ticked and dormant ones."
  7655.   (interactive "r\nP")
  7656.   (save-excursion
  7657.     (let (article)
  7658.       (goto-char point)
  7659.       (beginning-of-line)
  7660.       (while (and
  7661.           (< (point) mark)
  7662.           (progn
  7663.         (when (or all
  7664.               (memq (setq article (gnus-summary-article-number))
  7665.                 gnus-newsgroup-unreads))
  7666.           (gnus-summary-mark-article article gnus-del-mark))
  7667.         t)
  7668.           (gnus-summary-find-next))))))
  7669.  
  7670. (defun gnus-summary-mark-below (score mark)
  7671.   "Mark articles with score less than SCORE with MARK."
  7672.   (interactive "P\ncMark: ")
  7673.   (gnus-set-global-variables)
  7674.   (setq score (if score
  7675.           (prefix-numeric-value score)
  7676.         (or gnus-summary-default-score 0)))
  7677.   (save-excursion
  7678.     (set-buffer gnus-summary-buffer)
  7679.     (goto-char (point-min))
  7680.     (while
  7681.     (progn
  7682.       (and (< (gnus-summary-article-score) score)
  7683.            (gnus-summary-mark-article nil mark))
  7684.       (gnus-summary-find-next)))))
  7685.  
  7686. (defun gnus-summary-kill-below (&optional score)
  7687.   "Mark articles with score below SCORE as read."
  7688.   (interactive "P")
  7689.   (gnus-set-global-variables)
  7690.   (gnus-summary-mark-below score gnus-killed-mark))
  7691.  
  7692. (defun gnus-summary-clear-above (&optional score)
  7693.   "Clear all marks from articles with score above SCORE."
  7694.   (interactive "P")
  7695.   (gnus-set-global-variables)
  7696.   (gnus-summary-mark-above score gnus-unread-mark))
  7697.  
  7698. (defun gnus-summary-tick-above (&optional score)
  7699.   "Tick all articles with score above SCORE."
  7700.   (interactive "P")
  7701.   (gnus-set-global-variables)
  7702.   (gnus-summary-mark-above score gnus-ticked-mark))
  7703.  
  7704. (defun gnus-summary-mark-above (score mark)
  7705.   "Mark articles with score over SCORE with MARK."
  7706.   (interactive "P\ncMark: ")
  7707.   (gnus-set-global-variables)
  7708.   (setq score (if score
  7709.           (prefix-numeric-value score)
  7710.         (or gnus-summary-default-score 0)))
  7711.   (save-excursion
  7712.     (set-buffer gnus-summary-buffer)
  7713.     (goto-char (point-min))
  7714.     (while (and (progn
  7715.           (when (> (gnus-summary-article-score) score)
  7716.             (gnus-summary-mark-article nil mark))
  7717.           t)
  7718.         (gnus-summary-find-next)))))
  7719.  
  7720. ;; Suggested by Daniel Quinlan <quinlan@best.com>.
  7721. (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
  7722. (defun gnus-summary-limit-include-expunged (&optional no-error)
  7723.   "Display all the hidden articles that were expunged for low scores."
  7724.   (interactive)
  7725.   (gnus-set-global-variables)
  7726.   (let ((buffer-read-only nil))
  7727.     (let ((scored gnus-newsgroup-scored)
  7728.       headers h)
  7729.       (while scored
  7730.     (unless (gnus-summary-goto-subject (caar scored))
  7731.       (and (setq h (gnus-summary-article-header (caar scored)))
  7732.            (< (cdar scored) gnus-summary-expunge-below)
  7733.            (push h headers)))
  7734.     (setq scored (cdr scored)))
  7735.       (if (not headers)
  7736.       (when (not no-error)
  7737.         (error "No expunged articles hidden"))
  7738.     (goto-char (point-min))
  7739.     (gnus-summary-prepare-unthreaded (nreverse headers))
  7740.     (goto-char (point-min))
  7741.     (gnus-summary-position-point)
  7742.     t))))
  7743.  
  7744. (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
  7745.   "Mark all unread articles in this newsgroup as read.
  7746. If prefix argument ALL is non-nil, ticked and dormant articles will
  7747. also be marked as read.
  7748. If QUIETLY is non-nil, no questions will be asked.
  7749. If TO-HERE is non-nil, it should be a point in the buffer.  All
  7750. articles before this point will be marked as read.
  7751. Note that this function will only catch up the unread article
  7752. in the current summary buffer limitation.
  7753. The number of articles marked as read is returned."
  7754.   (interactive "P")
  7755.   (gnus-set-global-variables)
  7756.   (prog1
  7757.       (save-excursion
  7758.     (when (or quietly
  7759.           (not gnus-interactive-catchup) ;Without confirmation?
  7760.           gnus-expert-user
  7761.           (gnus-y-or-n-p
  7762.            (if all
  7763.                "Mark absolutely all articles as read? "
  7764.              "Mark all unread articles as read? ")))
  7765.       (if (and not-mark
  7766.            (not gnus-newsgroup-adaptive)
  7767.            (not gnus-newsgroup-auto-expire)
  7768.            (not gnus-suppress-duplicates)
  7769.            (or (not gnus-use-cache)
  7770.                (not (eq gnus-use-cache 'passive))))
  7771.           (progn
  7772.         (when all
  7773.           (setq gnus-newsgroup-marked nil
  7774.             gnus-newsgroup-dormant nil))
  7775.         (setq gnus-newsgroup-unreads nil))
  7776.         ;; We actually mark all articles as canceled, which we
  7777.         ;; have to do when using auto-expiry or adaptive scoring.
  7778.         (gnus-summary-show-all-threads)
  7779.         (when (gnus-summary-first-subject (not all))
  7780.           (while (and
  7781.               (if to-here (< (point) to-here) t)
  7782.               (gnus-summary-mark-article-as-read gnus-catchup-mark)
  7783.               (gnus-summary-find-next (not all)))))
  7784.         (gnus-set-mode-line 'summary))
  7785.       t))
  7786.     (gnus-summary-position-point)))
  7787.  
  7788. (defun gnus-summary-catchup-to-here (&optional all)
  7789.   "Mark all unticked articles before the current one as read.
  7790. If ALL is non-nil, also mark ticked and dormant articles as read."
  7791.   (interactive "P")
  7792.   (gnus-set-global-variables)
  7793.   (save-excursion
  7794.     (gnus-save-hidden-threads
  7795.       (let ((beg (point)))
  7796.     ;; We check that there are unread articles.
  7797.     (when (or all (gnus-summary-find-prev))
  7798.       (gnus-summary-catchup all t beg)))))
  7799.   (gnus-summary-position-point))
  7800.  
  7801. (defun gnus-summary-catchup-all (&optional quietly)
  7802.   "Mark all articles in this newsgroup as read."
  7803.   (interactive "P")
  7804.   (gnus-set-global-variables)
  7805.   (gnus-summary-catchup t quietly))
  7806.  
  7807. (defun gnus-summary-catchup-and-exit (&optional all quietly)
  7808.   "Mark all articles not marked as unread in this newsgroup as read, then exit.
  7809. If prefix argument ALL is non-nil, all articles are marked as read."
  7810.   (interactive "P")
  7811.   (gnus-set-global-variables)
  7812.   (when (gnus-summary-catchup all quietly nil 'fast)
  7813.     ;; Select next newsgroup or exit.
  7814.     (if (eq gnus-auto-select-next 'quietly)
  7815.     (gnus-summary-next-group nil)
  7816.       (gnus-summary-exit))))
  7817.  
  7818. (defun gnus-summary-catchup-all-and-exit (&optional quietly)
  7819.   "Mark all articles in this newsgroup as read, and then exit."
  7820.   (interactive "P")
  7821.   (gnus-set-global-variables)
  7822.   (gnus-summary-catchup-and-exit t quietly))
  7823.  
  7824. ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
  7825. (defun gnus-summary-catchup-and-goto-next-group (&optional all)
  7826.   "Mark all articles in this group as read and select the next group.
  7827. If given a prefix, mark all articles, unread as well as ticked, as
  7828. read."
  7829.   (interactive "P")
  7830.   (gnus-set-global-variables)
  7831.   (save-excursion
  7832.     (gnus-summary-catchup all))
  7833.   (gnus-summary-next-article t nil nil t))
  7834.  
  7835. ;; Thread-based commands.
  7836.  
  7837. (defun gnus-summary-articles-in-thread (&optional article)
  7838.   "Return a list of all articles in the current thread.
  7839. If ARTICLE is non-nil, return all articles in the thread that starts
  7840. with that article."
  7841.   (let* ((article (or article (gnus-summary-article-number)))
  7842.      (data (gnus-data-find-list article))
  7843.      (top-level (gnus-data-level (car data)))
  7844.      (top-subject
  7845.       (cond ((null gnus-thread-operation-ignore-subject)
  7846.          (gnus-simplify-subject-re
  7847.           (mail-header-subject (gnus-data-header (car data)))))
  7848.         ((eq gnus-thread-operation-ignore-subject 'fuzzy)
  7849.          (gnus-simplify-subject-fuzzy
  7850.           (mail-header-subject (gnus-data-header (car data)))))
  7851.         (t nil)))
  7852.      (end-point (save-excursion
  7853.               (if (gnus-summary-go-to-next-thread)
  7854.               (point) (point-max))))
  7855.      articles)
  7856.     (while (and data
  7857.         (< (gnus-data-pos (car data)) end-point))
  7858.       (when (or (not top-subject)
  7859.         (string= top-subject
  7860.              (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
  7861.                  (gnus-simplify-subject-fuzzy
  7862.                   (mail-header-subject
  7863.                    (gnus-data-header (car data))))
  7864.                (gnus-simplify-subject-re
  7865.                 (mail-header-subject
  7866.                  (gnus-data-header (car data)))))))
  7867.     (push (gnus-data-number (car data)) articles))
  7868.       (unless (and (setq data (cdr data))
  7869.            (> (gnus-data-level (car data)) top-level))
  7870.     (setq data nil)))
  7871.     ;; Return the list of articles.
  7872.     (nreverse articles)))
  7873.  
  7874. (defun gnus-summary-rethread-current ()
  7875.   "Rethread the thread the current article is part of."
  7876.   (interactive)
  7877.   (gnus-set-global-variables)
  7878.   (let* ((gnus-show-threads t)
  7879.      (article (gnus-summary-article-number))
  7880.      (id (mail-header-id (gnus-summary-article-header)))
  7881.      (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
  7882.     (unless id
  7883.       (error "No article on the current line"))
  7884.     (gnus-rebuild-thread id)
  7885.     (gnus-summary-goto-subject article)))
  7886.  
  7887. (defun gnus-summary-reparent-thread ()
  7888.   "Make the current article child of the marked (or previous) article.
  7889.  
  7890. Note that the re-threading will only work if `gnus-thread-ignore-subject'
  7891. is non-nil or the Subject: of both articles are the same."
  7892.   (interactive)
  7893.   (unless (not (gnus-group-read-only-p))
  7894.     (error "The current newsgroup does not support article editing"))
  7895.   (unless (<= (length gnus-newsgroup-processable) 1)
  7896.     (error "No more than one article may be marked"))
  7897.   (save-window-excursion
  7898.     (let ((gnus-article-buffer " *reparent*")
  7899.       (current-article (gnus-summary-article-number))
  7900.       ;; First grab the marked article, otherwise one line up.
  7901.       (parent-article (if (not (null gnus-newsgroup-processable))
  7902.                   (car gnus-newsgroup-processable)
  7903.                 (save-excursion
  7904.                   (if (eq (forward-line -1) 0)
  7905.                   (gnus-summary-article-number)
  7906.                 (error "Beginning of summary buffer"))))))
  7907.       (unless (not (eq current-article parent-article))
  7908.     (error "An article may not be self-referential"))
  7909.       (let ((message-id (mail-header-id
  7910.              (gnus-summary-article-header parent-article))))
  7911.     (unless (and message-id (not (equal message-id "")))
  7912.       (error "No message-id in desired parent"))
  7913.     (gnus-summary-select-article t t nil current-article)
  7914.     (set-buffer gnus-original-article-buffer)
  7915.     (let ((buf (format "%s" (buffer-string))))
  7916.       (nnheader-temp-write nil
  7917.         (insert buf)
  7918.         (goto-char (point-min))
  7919.         (if (search-forward-regexp "^References: " nil t)
  7920.         (insert message-id " " )
  7921.           (insert "References: " message-id "\n"))
  7922.         (unless (gnus-request-replace-article
  7923.              current-article (car gnus-article-current)
  7924.              (current-buffer))
  7925.           (error "Couldn't replace article"))))
  7926.     (set-buffer gnus-summary-buffer)
  7927.     (gnus-summary-unmark-all-processable)
  7928.     (gnus-summary-rethread-current)
  7929.     (gnus-message 3 "Article %d is now the child of article %d"
  7930.               current-article parent-article)))))
  7931.  
  7932. (defun gnus-summary-toggle-threads (&optional arg)
  7933.   "Toggle showing conversation threads.
  7934. If ARG is positive number, turn showing conversation threads on."
  7935.   (interactive "P")
  7936.   (gnus-set-global-variables)
  7937.   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
  7938.     (setq gnus-show-threads
  7939.       (if (null arg) (not gnus-show-threads)
  7940.         (> (prefix-numeric-value arg) 0)))
  7941.     (gnus-summary-prepare)
  7942.     (gnus-summary-goto-subject current)
  7943.     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
  7944.     (gnus-summary-position-point)))
  7945.  
  7946. (defun gnus-summary-show-all-threads ()
  7947.   "Show all threads."
  7948.   (interactive)
  7949.   (gnus-set-global-variables)
  7950.   (save-excursion
  7951.     (let ((buffer-read-only nil))
  7952.       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
  7953.   (gnus-summary-position-point))
  7954.  
  7955. (defun gnus-summary-show-thread ()
  7956.   "Show thread subtrees.
  7957. Returns nil if no thread was there to be shown."
  7958.   (interactive)
  7959.   (gnus-set-global-variables)
  7960.   (let ((buffer-read-only nil)
  7961.     (orig (point))
  7962.     ;; first goto end then to beg, to have point at beg after let
  7963.     (end (progn (end-of-line) (point)))
  7964.     (beg (progn (beginning-of-line) (point))))
  7965.     (prog1
  7966.     ;; Any hidden lines here?
  7967.     (search-forward "\r" end t)
  7968.       (subst-char-in-region beg end ?\^M ?\n t)
  7969.       (goto-char orig)
  7970.       (gnus-summary-position-point))))
  7971.  
  7972. (defun gnus-summary-hide-all-threads ()
  7973.   "Hide all thread subtrees."
  7974.   (interactive)
  7975.   (gnus-set-global-variables)
  7976.   (save-excursion
  7977.     (goto-char (point-min))
  7978.     (gnus-summary-hide-thread)
  7979.     (while (zerop (gnus-summary-next-thread 1 t))
  7980.       (gnus-summary-hide-thread)))
  7981.   (gnus-summary-position-point))
  7982.  
  7983. (defun gnus-summary-hide-thread ()
  7984.   "Hide thread subtrees.
  7985. Returns nil if no threads were there to be hidden."
  7986.   (interactive)
  7987.   (gnus-set-global-variables)
  7988.   (let ((buffer-read-only nil)
  7989.     (start (point))
  7990.     (article (gnus-summary-article-number)))
  7991.     (goto-char start)
  7992.     ;; Go forward until either the buffer ends or the subthread
  7993.     ;; ends.
  7994.     (when (and (not (eobp))
  7995.            (or (zerop (gnus-summary-next-thread 1 t))
  7996.            (goto-char (point-max))))
  7997.       (prog1
  7998.       (if (and (> (point) start)
  7999.            (search-backward "\n" start t))
  8000.           (progn
  8001.         (subst-char-in-region start (point) ?\n ?\^M)
  8002.         (gnus-summary-goto-subject article))
  8003.         (goto-char start)
  8004.         nil)
  8005.     ;;(gnus-summary-position-point)
  8006.     ))))
  8007.  
  8008. (defun gnus-summary-go-to-next-thread (&optional previous)
  8009.   "Go to the same level (or less) next thread.
  8010. If PREVIOUS is non-nil, go to previous thread instead.
  8011. Return the article number moved to, or nil if moving was impossible."
  8012.   (let ((level (gnus-summary-thread-level))
  8013.     (way (if previous -1 1))
  8014.     (beg (point)))
  8015.     (forward-line way)
  8016.     (while (and (not (eobp))
  8017.         (< level (gnus-summary-thread-level)))
  8018.       (forward-line way))
  8019.     (if (eobp)
  8020.     (progn
  8021.       (goto-char beg)
  8022.       nil)
  8023.       (setq beg (point))
  8024.       (prog1
  8025.       (gnus-summary-article-number)
  8026.     (goto-char beg)))))
  8027.  
  8028. (defun gnus-summary-next-thread (n &optional silent)
  8029.   "Go to the same level next N'th thread.
  8030. If N is negative, search backward instead.
  8031. Returns the difference between N and the number of skips actually
  8032. done.
  8033.  
  8034. If SILENT, don't output messages."
  8035.   (interactive "p")
  8036.   (gnus-set-global-variables)
  8037.   (let ((backward (< n 0))
  8038.     (n (abs n)))
  8039.     (while (and (> n 0)
  8040.         (gnus-summary-go-to-next-thread backward))
  8041.       (decf n))
  8042.     (unless silent
  8043.       (gnus-summary-position-point))
  8044.     (when (and (not silent) (/= 0 n))
  8045.       (gnus-message 7 "No more threads"))
  8046.     n))
  8047.  
  8048. (defun gnus-summary-prev-thread (n)
  8049.   "Go to the same level previous N'th thread.
  8050. Returns the difference between N and the number of skips actually
  8051. done."
  8052.   (interactive "p")
  8053.   (gnus-set-global-variables)
  8054.   (gnus-summary-next-thread (- n)))
  8055.  
  8056. (defun gnus-summary-go-down-thread ()
  8057.   "Go down one level in the current thread."
  8058.   (let ((children (gnus-summary-article-children)))
  8059.     (when children
  8060.       (gnus-summary-goto-subject (car children)))))
  8061.  
  8062. (defun gnus-summary-go-up-thread ()
  8063.   "Go up one level in the current thread."
  8064.   (let ((parent (gnus-summary-article-parent)))
  8065.     (when parent
  8066.       (gnus-summary-goto-subject parent))))
  8067.  
  8068. (defun gnus-summary-down-thread (n)
  8069.   "Go down thread N steps.
  8070. If N is negative, go up instead.
  8071. Returns the difference between N and how many steps down that were
  8072. taken."
  8073.   (interactive "p")
  8074.   (gnus-set-global-variables)
  8075.   (let ((up (< n 0))
  8076.     (n (abs n)))
  8077.     (while (and (> n 0)
  8078.         (if up (gnus-summary-go-up-thread)
  8079.           (gnus-summary-go-down-thread)))
  8080.       (setq n (1- n)))
  8081.     (gnus-summary-position-point)
  8082.     (when (/= 0 n)
  8083.       (gnus-message 7 "Can't go further"))
  8084.     n))
  8085.  
  8086. (defun gnus-summary-up-thread (n)
  8087.   "Go up thread N steps.
  8088. If N is negative, go up instead.
  8089. Returns the difference between N and how many steps down that were
  8090. taken."
  8091.   (interactive "p")
  8092.   (gnus-set-global-variables)
  8093.   (gnus-summary-down-thread (- n)))
  8094.  
  8095. (defun gnus-summary-top-thread ()
  8096.   "Go to the top of the thread."
  8097.   (interactive)
  8098.   (gnus-set-global-variables)
  8099.   (while (gnus-summary-go-up-thread))
  8100.   (gnus-summary-article-number))
  8101.  
  8102. (defun gnus-summary-kill-thread (&optional unmark)
  8103.   "Mark articles under current thread as read.
  8104. If the prefix argument is positive, remove any kinds of marks.
  8105. If the prefix argument is negative, tick articles instead."
  8106.   (interactive "P")
  8107.   (gnus-set-global-variables)
  8108.   (when unmark
  8109.     (setq unmark (prefix-numeric-value unmark)))
  8110.   (let ((articles (gnus-summary-articles-in-thread)))
  8111.     (save-excursion
  8112.       ;; Expand the thread.
  8113.       (gnus-summary-show-thread)
  8114.       ;; Mark all the articles.
  8115.       (while articles
  8116.     (gnus-summary-goto-subject (car articles))
  8117.     (cond ((null unmark)
  8118.            (gnus-summary-mark-article-as-read gnus-killed-mark))
  8119.           ((> unmark 0)
  8120.            (gnus-summary-mark-article-as-unread gnus-unread-mark))
  8121.           (t
  8122.            (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
  8123.     (setq articles (cdr articles))))
  8124.     ;; Hide killed subtrees.
  8125.     (and (null unmark)
  8126.      gnus-thread-hide-killed
  8127.      (gnus-summary-hide-thread))
  8128.     ;; If marked as read, go to next unread subject.
  8129.     (when (null unmark)
  8130.       ;; Go to next unread subject.
  8131.       (gnus-summary-next-subject 1 t)))
  8132.   (gnus-set-mode-line 'summary))
  8133.  
  8134. ;; Summary sorting commands
  8135.  
  8136. (defun gnus-summary-sort-by-number (&optional reverse)
  8137.   "Sort the summary buffer by article number.
  8138. Argument REVERSE means reverse order."
  8139.   (interactive "P")
  8140.   (gnus-summary-sort 'number reverse))
  8141.  
  8142. (defun gnus-summary-sort-by-author (&optional reverse)
  8143.   "Sort the summary buffer by author name alphabetically.
  8144. If case-fold-search is non-nil, case of letters is ignored.
  8145. Argument REVERSE means reverse order."
  8146.   (interactive "P")
  8147.   (gnus-summary-sort 'author reverse))
  8148.  
  8149. (defun gnus-summary-sort-by-subject (&optional reverse)
  8150.   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
  8151. If case-fold-search is non-nil, case of letters is ignored.
  8152. Argument REVERSE means reverse order."
  8153.   (interactive "P")
  8154.   (gnus-summary-sort 'subject reverse))
  8155.  
  8156. (defun gnus-summary-sort-by-date (&optional reverse)
  8157.   "Sort the summary buffer by date.
  8158. Argument REVERSE means reverse order."
  8159.   (interactive "P")
  8160.   (gnus-summary-sort 'date reverse))
  8161.  
  8162. (defun gnus-summary-sort-by-score (&optional reverse)
  8163.   "Sort the summary buffer by score.
  8164. Argument REVERSE means reverse order."
  8165.   (interactive "P")
  8166.   (gnus-summary-sort 'score reverse))
  8167.  
  8168. (defun gnus-summary-sort-by-lines (&optional reverse)
  8169.   "Sort the summary buffer by article length.
  8170. Argument REVERSE means reverse order."
  8171.   (interactive "P")
  8172.   (gnus-summary-sort 'lines reverse))
  8173.  
  8174. (defun gnus-summary-sort (predicate reverse)
  8175.   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
  8176.   (gnus-set-global-variables)
  8177.   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
  8178.      (article (intern (format "gnus-article-sort-by-%s" predicate)))
  8179.      (gnus-thread-sort-functions
  8180.       (list
  8181.        (if (not reverse)
  8182.            thread
  8183.          `(lambda (t1 t2)
  8184.         (,thread t2 t1)))))
  8185.      (gnus-article-sort-functions
  8186.       (list
  8187.        (if (not reverse)
  8188.            article
  8189.          `(lambda (t1 t2)
  8190.         (,article t2 t1)))))
  8191.      (buffer-read-only)
  8192.      (gnus-summary-prepare-hook nil))
  8193.     ;; We do the sorting by regenerating the threads.
  8194.     (gnus-summary-prepare)
  8195.     ;; Hide subthreads if needed.
  8196.     (when (and gnus-show-threads gnus-thread-hide-subtree)
  8197.       (gnus-summary-hide-all-threads))))
  8198.  
  8199. ;; Summary saving commands.
  8200.  
  8201. (defun gnus-summary-save-article (&optional n not-saved)
  8202.   "Save the current article using the default saver function.
  8203. If N is a positive number, save the N next articles.
  8204. If N is a negative number, save the N previous articles.
  8205. If N is nil and any articles have been marked with the process mark,
  8206. save those articles instead.
  8207. The variable `gnus-default-article-saver' specifies the saver function."
  8208.   (interactive "P")
  8209.   (gnus-set-global-variables)
  8210.   (let* ((articles (gnus-summary-work-articles n))
  8211.      (save-buffer (save-excursion
  8212.             (nnheader-set-temp-buffer " *Gnus Save*")))
  8213.      (num (length articles))
  8214.      header article file)
  8215.     (while articles
  8216.       (setq header (gnus-summary-article-header
  8217.             (setq article (pop articles))))
  8218.       (if (not (vectorp header))
  8219.       ;; This is a pseudo-article.
  8220.       (if (assq 'name header)
  8221.           (gnus-copy-file (cdr (assq 'name header)))
  8222.         (gnus-message 1 "Article %d is unsaveable" article))
  8223.     ;; This is a real article.
  8224.     (save-window-excursion
  8225.       (gnus-summary-select-article t nil nil article))
  8226.     (save-excursion
  8227.       (set-buffer save-buffer)
  8228.       (erase-buffer)
  8229.       (insert-buffer-substring gnus-original-article-buffer))
  8230.     (setq file (gnus-article-save save-buffer file num))
  8231.     (gnus-summary-remove-process-mark article)
  8232.     (unless not-saved
  8233.       (gnus-summary-set-saved-mark article))))
  8234.     (gnus-kill-buffer save-buffer)
  8235.     (gnus-summary-position-point)
  8236.     (gnus-set-mode-line 'summary)
  8237.     n))
  8238.  
  8239. (defun gnus-summary-pipe-output (&optional arg)
  8240.   "Pipe the current article to a subprocess.
  8241. If N is a positive number, pipe the N next articles.
  8242. If N is a negative number, pipe the N previous articles.
  8243. If N is nil and any articles have been marked with the process mark,
  8244. pipe those articles instead."
  8245.   (interactive "P")
  8246.   (gnus-set-global-variables)
  8247.   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
  8248.     (gnus-summary-save-article arg t))
  8249.   (gnus-configure-windows 'pipe))
  8250.  
  8251. (defun gnus-summary-save-article-mail (&optional arg)
  8252.   "Append the current article to an mail file.
  8253. If N is a positive number, save the N next articles.
  8254. If N is a negative number, save the N previous articles.
  8255. If N is nil and any articles have been marked with the process mark,
  8256. save those articles instead."
  8257.   (interactive "P")
  8258.   (gnus-set-global-variables)
  8259.   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
  8260.     (gnus-summary-save-article arg)))
  8261.  
  8262. (defun gnus-summary-save-article-rmail (&optional arg)
  8263.   "Append the current article to an rmail file.
  8264. If N is a positive number, save the N next articles.
  8265. If N is a negative number, save the N previous articles.
  8266. If N is nil and any articles have been marked with the process mark,
  8267. save those articles instead."
  8268.   (interactive "P")
  8269.   (gnus-set-global-variables)
  8270.   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
  8271.     (gnus-summary-save-article arg)))
  8272.  
  8273. (defun gnus-summary-save-article-file (&optional arg)
  8274.   "Append the current article to a file.
  8275. If N is a positive number, save the N next articles.
  8276. If N is a negative number, save the N previous articles.
  8277. If N is nil and any articles have been marked with the process mark,
  8278. save those articles instead."
  8279.   (interactive "P")
  8280.   (gnus-set-global-variables)
  8281.   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
  8282.     (gnus-summary-save-article arg)))
  8283.  
  8284. (defun gnus-summary-write-article-file (&optional arg)
  8285.   "Write the current article to a file, deleting the previous file.
  8286. If N is a positive number, save the N next articles.
  8287. If N is a negative number, save the N previous articles.
  8288. If N is nil and any articles have been marked with the process mark,
  8289. save those articles instead."
  8290.   (interactive "P")
  8291.   (gnus-set-global-variables)
  8292.   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
  8293.     (gnus-summary-save-article arg)))
  8294.  
  8295. (defun gnus-summary-save-article-body-file (&optional arg)
  8296.   "Append the current article body to a file.
  8297. If N is a positive number, save the N next articles.
  8298. If N is a negative number, save the N previous articles.
  8299. If N is nil and any articles have been marked with the process mark,
  8300. save those articles instead."
  8301.   (interactive "P")
  8302.   (gnus-set-global-variables)
  8303.   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
  8304.     (gnus-summary-save-article arg)))
  8305.  
  8306. (defun gnus-summary-pipe-message (program)
  8307.   "Pipe the current article through PROGRAM."
  8308.   (interactive "sProgram: ")
  8309.   (gnus-set-global-variables)
  8310.   (gnus-summary-select-article)
  8311.   (let ((mail-header-separator "")
  8312.         (art-buf (get-buffer gnus-article-buffer)))
  8313.     (gnus-eval-in-buffer-window gnus-article-buffer
  8314.       (save-restriction
  8315.         (widen)
  8316.         (let ((start (window-start))
  8317.               buffer-read-only)
  8318.           (message-pipe-buffer-body program)
  8319.           (set-window-start (get-buffer-window (current-buffer)) start))))))
  8320.  
  8321. (defun gnus-get-split-value (methods)
  8322.   "Return a value based on the split METHODS."
  8323.   (let (split-name method result match)
  8324.     (when methods
  8325.       (save-excursion
  8326.     (set-buffer gnus-original-article-buffer)
  8327.     (save-restriction
  8328.       (nnheader-narrow-to-headers)
  8329.       (while methods
  8330.         (goto-char (point-min))
  8331.         (setq method (pop methods))
  8332.         (setq match (car method))
  8333.         (when (cond
  8334.            ((stringp match)
  8335.             ;; Regular expression.
  8336.             (ignore-errors
  8337.               (re-search-forward match nil t)))
  8338.            ((gnus-functionp match)
  8339.             ;; Function.
  8340.             (save-restriction
  8341.               (widen)
  8342.               (setq result (funcall match gnus-newsgroup-name))))
  8343.            ((consp match)
  8344.             ;; Form.
  8345.             (save-restriction
  8346.               (widen)
  8347.               (setq result (eval match)))))
  8348.           (setq split-name (append (cdr method) split-name))
  8349.           (cond ((stringp result)
  8350.              (push (expand-file-name
  8351.                 result gnus-article-save-directory)
  8352.                split-name))
  8353.             ((consp result)
  8354.              (setq split-name (append result split-name)))))))))
  8355.     split-name))
  8356.  
  8357. (defun gnus-valid-move-group-p (group)
  8358.   (and (boundp group)
  8359.        (symbol-name group)
  8360.        (memq 'respool
  8361.          (assoc (symbol-name
  8362.              (car (gnus-find-method-for-group
  8363.                (symbol-name group))))
  8364.             gnus-valid-select-methods))))
  8365.  
  8366. (defun gnus-read-move-group-name (prompt default articles prefix)
  8367.   "Read a group name."
  8368.   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
  8369.      (minibuffer-confirm-incomplete nil) ; XEmacs
  8370.      (prom
  8371.       (format "%s %s to:"
  8372.           prompt
  8373.           (if (> (length articles) 1)
  8374.               (format "these %d articles" (length articles))
  8375.             "this article")))
  8376.      (to-newsgroup
  8377.       (cond
  8378.        ((null split-name)
  8379.         (gnus-completing-read default prom
  8380.                   gnus-active-hashtb
  8381.                   'gnus-valid-move-group-p
  8382.                   nil prefix
  8383.                   'gnus-group-history))
  8384.        ((= 1 (length split-name))
  8385.         (gnus-completing-read (car split-name) prom
  8386.                   gnus-active-hashtb
  8387.                   'gnus-valid-move-group-p
  8388.                   nil nil
  8389.                   'gnus-group-history))
  8390.        (t
  8391.         (gnus-completing-read nil prom
  8392.                   (mapcar (lambda (el) (list el))
  8393.                       (nreverse split-name))
  8394.                   nil nil nil
  8395.                   'gnus-group-history)))))
  8396.     (when to-newsgroup
  8397.       (if (or (string= to-newsgroup "")
  8398.           (string= to-newsgroup prefix))
  8399.       (setq to-newsgroup default))
  8400.       (unless to-newsgroup
  8401.     (error "No group name entered"))
  8402.       (or (gnus-active to-newsgroup)
  8403.       (gnus-activate-group to-newsgroup)
  8404.       (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
  8405.                      to-newsgroup))
  8406.           (or (and (gnus-request-create-group
  8407.             to-newsgroup (gnus-group-name-to-method to-newsgroup))
  8408.                (gnus-activate-group to-newsgroup nil nil
  8409.                         (gnus-group-name-to-method
  8410.                          to-newsgroup)))
  8411.           (error "Couldn't create group %s" to-newsgroup)))
  8412.       (error "No such group: %s" to-newsgroup)))
  8413.     to-newsgroup))
  8414.  
  8415. ;; Summary extract commands
  8416.  
  8417. (defun gnus-summary-insert-pseudos (pslist &optional not-view)
  8418.   (let ((buffer-read-only nil)
  8419.     (article (gnus-summary-article-number))
  8420.     after-article b e)
  8421.     (unless (gnus-summary-goto-subject article)
  8422.       (error "No such article: %d" article))
  8423.     (gnus-summary-position-point)
  8424.     ;; If all commands are to be bunched up on one line, we collect
  8425.     ;; them here.
  8426.     (unless gnus-view-pseudos-separately
  8427.       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
  8428.         files action)
  8429.     (while ps
  8430.       (setq action (cdr (assq 'action (car ps))))
  8431.       (setq files (list (cdr (assq 'name (car ps)))))
  8432.       (while (and ps (cdr ps)
  8433.               (string= (or action "1")
  8434.                    (or (cdr (assq 'action (cadr ps))) "2")))
  8435.         (push (cdr (assq 'name (cadr ps))) files)
  8436.         (setcdr ps (cddr ps)))
  8437.       (when files
  8438.         (when (not (string-match "%s" action))
  8439.           (push " " files))
  8440.         (push " " files)
  8441.         (when (assq 'execute (car ps))
  8442.           (setcdr (assq 'execute (car ps))
  8443.               (funcall (if (string-match "%s" action)
  8444.                    'format 'concat)
  8445.                    action
  8446.                    (mapconcat
  8447.                 (lambda (f)
  8448.                   (if (equal f " ")
  8449.                       f
  8450.                     (gnus-quote-arg-for-sh-or-csh f)))
  8451.                 files " ")))))
  8452.       (setq ps (cdr ps)))))
  8453.     (if (and gnus-view-pseudos (not not-view))
  8454.     (while pslist
  8455.       (when (assq 'execute (car pslist))
  8456.         (gnus-execute-command (cdr (assq 'execute (car pslist)))
  8457.                   (eq gnus-view-pseudos 'not-confirm)))
  8458.       (setq pslist (cdr pslist)))
  8459.       (save-excursion
  8460.     (while pslist
  8461.       (setq after-article (or (cdr (assq 'article (car pslist)))
  8462.                   (gnus-summary-article-number)))
  8463.       (gnus-summary-goto-subject after-article)
  8464.       (forward-line 1)
  8465.       (setq b (point))
  8466.       (insert "    " (file-name-nondirectory
  8467.               (cdr (assq 'name (car pslist))))
  8468.           ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
  8469.       (setq e (point))
  8470.       (forward-line -1)        ; back to `b'
  8471.       (gnus-add-text-properties
  8472.        b (1- e) (list 'gnus-number gnus-reffed-article-number
  8473.               gnus-mouse-face-prop gnus-mouse-face))
  8474.       (gnus-data-enter
  8475.        after-article gnus-reffed-article-number
  8476.        gnus-unread-mark b (car pslist) 0 (- e b))
  8477.       (push gnus-reffed-article-number gnus-newsgroup-unreads)
  8478.       (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
  8479.       (setq pslist (cdr pslist)))))))
  8480.  
  8481. (defun gnus-pseudos< (p1 p2)
  8482.   (let ((c1 (cdr (assq 'action p1)))
  8483.     (c2 (cdr (assq 'action p2))))
  8484.     (and c1 c2 (string< c1 c2))))
  8485.  
  8486. (defun gnus-request-pseudo-article (props)
  8487.   (cond ((assq 'execute props)
  8488.      (gnus-execute-command (cdr (assq 'execute props)))))
  8489.   (let ((gnus-current-article (gnus-summary-article-number)))
  8490.     (run-hooks 'gnus-mark-article-hook)))
  8491.  
  8492. (defun gnus-execute-command (command &optional automatic)
  8493.   (save-excursion
  8494.     (gnus-article-setup-buffer)
  8495.     (set-buffer gnus-article-buffer)
  8496.     (setq buffer-read-only nil)
  8497.     (let ((command (if automatic command
  8498.              (read-string "Command: " (cons command 0)))))
  8499.       (erase-buffer)
  8500.       (insert "$ " command "\n\n")
  8501.       (if gnus-view-pseudo-asynchronously
  8502.       (start-process "gnus-execute" (current-buffer) shell-file-name
  8503.              shell-command-switch command)
  8504.     (call-process shell-file-name nil t nil
  8505.               shell-command-switch command)))))
  8506.  
  8507. ;; Summary kill commands.
  8508.  
  8509. (defun gnus-summary-edit-global-kill (article)
  8510.   "Edit the \"global\" kill file."
  8511.   (interactive (list (gnus-summary-article-number)))
  8512.   (gnus-set-global-variables)
  8513.   (gnus-group-edit-global-kill article))
  8514.  
  8515. (defun gnus-summary-edit-local-kill ()
  8516.   "Edit a local kill file applied to the current newsgroup."
  8517.   (interactive)
  8518.   (gnus-set-global-variables)
  8519.   (setq gnus-current-headers (gnus-summary-article-header))
  8520.   (gnus-set-global-variables)
  8521.   (gnus-group-edit-local-kill
  8522.    (gnus-summary-article-number) gnus-newsgroup-name))
  8523.  
  8524. ;;; Header reading.
  8525.  
  8526. (defun gnus-read-header (id &optional header)
  8527.   "Read the headers of article ID and enter them into the Gnus system."
  8528.   (let ((group gnus-newsgroup-name)
  8529.     (gnus-override-method
  8530.      (and (gnus-news-group-p gnus-newsgroup-name)
  8531.           gnus-refer-article-method))
  8532.     where)
  8533.     ;; First we check to see whether the header in question is already
  8534.     ;; fetched.
  8535.     (if (stringp id)
  8536.     ;; This is a Message-ID.
  8537.     (setq header (or header (gnus-id-to-header id)))
  8538.       ;; This is an article number.
  8539.       (setq header (or header (gnus-summary-article-header id))))
  8540.     (if (and header
  8541.          (not (gnus-summary-article-sparse-p (mail-header-number header))))
  8542.     ;; We have found the header.
  8543.     header
  8544.       ;; We have to really fetch the header to this article.
  8545.       (save-excursion
  8546.     (set-buffer nntp-server-buffer)
  8547.     (when (setq where (gnus-request-head id group))
  8548.       (nnheader-fold-continuation-lines)
  8549.       (goto-char (point-max))
  8550.       (insert ".\n")
  8551.       (goto-char (point-min))
  8552.       (insert "211 ")
  8553.       (princ (cond
  8554.           ((numberp id) id)
  8555.           ((cdr where) (cdr where))
  8556.           (header (mail-header-number header))
  8557.           (t gnus-reffed-article-number))
  8558.          (current-buffer))
  8559.       (insert " Article retrieved.\n"))
  8560.     (if (or (not where)
  8561.         (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
  8562.         ()                ; Malformed head.
  8563.       (unless (gnus-summary-article-sparse-p (mail-header-number header))
  8564.         (when (and (stringp id)
  8565.                (not (string= (gnus-group-real-name group)
  8566.                      (car where))))
  8567.           ;; If we fetched by Message-ID and the article came
  8568.           ;; from a different group, we fudge some bogus article
  8569.           ;; numbers for this article.
  8570.           (mail-header-set-number header gnus-reffed-article-number))
  8571.         (save-excursion
  8572.           (set-buffer gnus-summary-buffer)
  8573.           (decf gnus-reffed-article-number)
  8574.           (gnus-remove-header (mail-header-number header))
  8575.           (push header gnus-newsgroup-headers)
  8576.           (setq gnus-current-headers header)
  8577.           (push (mail-header-number header) gnus-newsgroup-limit)))
  8578.       header)))))
  8579.  
  8580. (defun gnus-remove-header (number)
  8581.   "Remove header NUMBER from `gnus-newsgroup-headers'."
  8582.   (if (and gnus-newsgroup-headers
  8583.        (= number (mail-header-number (car gnus-newsgroup-headers))))
  8584.       (pop gnus-newsgroup-headers)
  8585.     (let ((headers gnus-newsgroup-headers))
  8586.       (while (and (cdr headers)
  8587.           (not (= number (mail-header-number (cadr headers)))))
  8588.     (pop headers))
  8589.       (when (cdr headers)
  8590.     (setcdr headers (cddr headers))))))
  8591.  
  8592. ;;;
  8593. ;;; summary highlights
  8594. ;;;
  8595.  
  8596. (defun gnus-highlight-selected-summary ()
  8597.   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
  8598.   ;; Highlight selected article in summary buffer
  8599.   (when gnus-summary-selected-face
  8600.     (save-excursion
  8601.       (let* ((beg (progn (beginning-of-line) (point)))
  8602.          (end (progn (end-of-line) (point)))
  8603.          ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
  8604.          (from (if (get-text-property beg gnus-mouse-face-prop)
  8605.                beg
  8606.              (or (next-single-property-change
  8607.               beg gnus-mouse-face-prop nil end)
  8608.              beg)))
  8609.          (to
  8610.           (if (= from end)
  8611.           (- from 2)
  8612.         (or (next-single-property-change
  8613.              from gnus-mouse-face-prop nil end)
  8614.             end))))
  8615.     ;; If no mouse-face prop on line we will have to = from = end,
  8616.     ;; so we highlight the entire line instead.
  8617.     (when (= (+ to 2) from)
  8618.       (setq from beg)
  8619.       (setq to end))
  8620.     (if gnus-newsgroup-selected-overlay
  8621.         ;; Move old overlay.
  8622.         (gnus-move-overlay
  8623.          gnus-newsgroup-selected-overlay from to (current-buffer))
  8624.       ;; Create new overlay.
  8625.       (gnus-overlay-put
  8626.        (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
  8627.        'face gnus-summary-selected-face))))))
  8628.  
  8629. ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
  8630. (defun gnus-summary-highlight-line ()
  8631.   "Highlight current line according to `gnus-summary-highlight'."
  8632.   (let* ((list gnus-summary-highlight)
  8633.      (p (point))
  8634.      (end (progn (end-of-line) (point)))
  8635.      ;; now find out where the line starts and leave point there.
  8636.      (beg (progn (beginning-of-line) (point)))
  8637.      (article (gnus-summary-article-number))
  8638.      (score (or (cdr (assq (or article gnus-current-article)
  8639.                    gnus-newsgroup-scored))
  8640.             gnus-summary-default-score 0))
  8641.      (mark (or (gnus-summary-article-mark) gnus-unread-mark))
  8642.      (inhibit-read-only t))
  8643.     ;; Eval the cars of the lists until we find a match.
  8644.     (let ((default gnus-summary-default-score))
  8645.       (while (and list
  8646.           (not (eval (caar list))))
  8647.     (setq list (cdr list))))
  8648.     (let ((face (cdar list)))
  8649.       (unless (eq face (get-text-property beg 'face))
  8650.     (gnus-put-text-property
  8651.      beg end 'face
  8652.      (setq face (if (boundp face) (symbol-value face) face)))
  8653.     (when gnus-summary-highlight-line-function
  8654.       (funcall gnus-summary-highlight-line-function article face))))
  8655.     (goto-char p)))
  8656.  
  8657. (defun gnus-update-read-articles (group unread)
  8658.   "Update the list of read articles in GROUP."
  8659.   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
  8660.      (entry (gnus-gethash group gnus-newsrc-hashtb))
  8661.      (info (nth 2 entry))
  8662.      (prev 1)
  8663.      (unread (sort (copy-sequence unread) '<))
  8664.      read)
  8665.     (if (or (not info) (not active))
  8666.     ;; There is no info on this group if it was, in fact,
  8667.     ;; killed.  Gnus stores no information on killed groups, so
  8668.     ;; there's nothing to be done.
  8669.     ;; One could store the information somewhere temporarily,
  8670.     ;; perhaps...  Hmmm...
  8671.     ()
  8672.       ;; Remove any negative articles numbers.
  8673.       (while (and unread (< (car unread) 0))
  8674.     (setq unread (cdr unread)))
  8675.       ;; Remove any expired article numbers
  8676.       (while (and unread (< (car unread) (car active)))
  8677.     (setq unread (cdr unread)))
  8678.       ;; Compute the ranges of read articles by looking at the list of
  8679.       ;; unread articles.
  8680.       (while unread
  8681.     (when (/= (car unread) prev)
  8682.       (push (if (= prev (1- (car unread))) prev
  8683.           (cons prev (1- (car unread))))
  8684.         read))
  8685.     (setq prev (1+ (car unread)))
  8686.     (setq unread (cdr unread)))
  8687.       (when (<= prev (cdr active))
  8688.     (push (cons prev (cdr active)) read))
  8689.       (save-excursion
  8690.     (set-buffer gnus-group-buffer)
  8691.     (gnus-undo-register
  8692.       `(progn
  8693.          (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
  8694.          (gnus-info-set-read ',info ',(gnus-info-read info))
  8695.          (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
  8696.          (gnus-group-update-group ,group t))))
  8697.       ;; Enter this list into the group info.
  8698.       (gnus-info-set-read
  8699.        info (if (> (length read) 1) (nreverse read) read))
  8700.       ;; Set the number of unread articles in gnus-newsrc-hashtb.
  8701.       (gnus-get-unread-articles-in-group info (gnus-active group))
  8702.       t)))
  8703.  
  8704. (defun gnus-offer-save-summaries ()
  8705.   "Offer to save all active summary buffers."
  8706.   (save-excursion
  8707.     (let ((buflist (buffer-list))
  8708.       buffers bufname)
  8709.       ;; Go through all buffers and find all summaries.
  8710.       (while buflist
  8711.     (and (setq bufname (buffer-name (car buflist)))
  8712.          (string-match "Summary" bufname)
  8713.          (save-excursion
  8714.            (set-buffer bufname)
  8715.            ;; We check that this is, indeed, a summary buffer.
  8716.            (and (eq major-mode 'gnus-summary-mode)
  8717.             ;; Also make sure this isn't bogus.
  8718.             gnus-newsgroup-prepared
  8719.             ;; Also make sure that this isn't a dead summary buffer.
  8720.             (not gnus-dead-summary-mode)))
  8721.          (push bufname buffers))
  8722.     (setq buflist (cdr buflist)))
  8723.       ;; Go through all these summary buffers and offer to save them.
  8724.       (when buffers
  8725.     (map-y-or-n-p
  8726.      "Update summary buffer %s? "
  8727.      (lambda (buf) (switch-to-buffer buf) (gnus-summary-exit))
  8728.      buffers)))))
  8729.  
  8730. (gnus-ems-redefine)
  8731.  
  8732. (provide 'gnus-sum)
  8733.  
  8734. (run-hooks 'gnus-sum-load-hook)
  8735.  
  8736. ;;; gnus-sum.el ends here
  8737.